Interface Type
The complete COM programming system is based on an interface. The interface can be divided into the following categories:
n Standard Interface The interface provided by the COM system
N Custom Interface The interface created by the developer
Most methods implemented by standard interfaces are called by the system. Such standard interfaces include IunkNown, Idispatch, IclassFactory, Iole, IdateObject, IStream, iStorage ...
The purpose of custom interface is to provide more features to users.
Standard interface
Different standard interfaces provided by the COM system are:
n iUnknown iUnknown is the base connection of all interfaces. Even custom interfaces are also executed IUNKNOWN. All COM components must implement this interface. IUNKNOWN is used for lifecycle management of component objects. It can also query other interfaces used by the components object.
The following equation clarifies the relationship between C objects and COM objects:
C object iUnknown = COM object
IUNKNOWN interface is used for lifecycle management of component objects, which performs this function below.
n addref
N release
Component objects can be used by multiple applications. Each time you execute an application, you need to load the components into memory. At 32-bit Windows, such as Windows NT, each time the application requests the component, the copy is mapped to the address space of the application. And increase the reference count; Similar, each application and component are disconnected, the reference count is reduced. The operating system maintains the connection count in which the component object exists. When the count drops into 0, it hints that there is no application access component and destroy the components.
Component's reference count uses functions addRef and Release maintenance. AddRef adds counts; Release is responsible for reducing counting.
IUNKNOWN has a function called QueryInterface that provides a list of supported interfaces. QueryInterface method has two parameters, the first is an interface identifier that identifies the required interface, the second is a pointer to the QueryInterFace store address address. Therefore, queryInterface is used to provide a pointer to the interface to access the component's functionality.
n iDispatch When the client is normal, the scripting language or the Visual Basic application calls the function of the component object, the iDispatch interface query function, and execute it. Use iDispatch when the components are called each other.
The IDSPATCH interface is implemented for components that need to interact with customers who do not support pointers such as customers, especially Visual Basic and scripting languages. Consider an instance, the Visual Basic application stores data in the Microsoft Access database and creates a chart using Microsoft Excel. Here, Visual Basic and Microsoft Access database components and Microsoft Excel chart components interact. This only all components implement the iDispatch interface.
The IDISPATCH interface is used to expose the standard interface of the component function. However, it increases the overhead of the system due to the need to call the system function sequentially.
n iClassFactory IclassFactory interface is used to create an instance of a new COM object.
To now, you are familiar with the different types of components, namely, local and remote. Suppose your component is a process within a process, how do you create an instance of the class? The answer is the C new operator. But if the component is local or remote? So, it is clear that the New operator is not an answer.
The answer to this question is the IclassFactory interface.
The IClassFactory interface is an interface for instances of another local class or remote class for a particular design to create another local class or remote class.
There are two ways for CreateInstance and LockServer.
The CREATEINSTANCE method actually creates an instance of a COM object. The LOCKSERVER method is used to keep the component in memory so that the instance is allowed to be faster.
n Iole ioleObject is a major interface that implements the Nested OLE object. IOLELINK is the primary interface using the OLE object link.
n iDataObject is used to implement the interface of the drag and drop function.
N iStream and iStorage IStream and iStorage interfaces are used to create and manage storage objects. These interfaces typically use the OLE applications from multiple sources.
IdataObject, iStream, and iStorage three connections use the Unified Data Transfer Protocol (UDT), which describes the exchange criteria for different types of applications.
summary
Why do I need a component object model CoM?
The COM component is a program or binary object that performs a specific operation. COM defines the system, component interaction, protocol standards, and components to ensure interoperability of components. The COM specification is embodied in the COM runtime library, which provides the ability to call components in the process, processes and cross-network.
What is the working principle of COM?
COM allows you to create independent, reusable, unconfigured components that form applications. In COM, interoperability between components is based on a client / server model. Component objects are highly packaged. The internal implementation of the component object is completely hidden. Each component has an interface, and the interface is the only way to access component object functions.
What is the characteristics of the interface?
The interface does not have any implementation, so all interfaces cannot be instantiated. The interface is non-versioned and cannot be changed.
What is UUID / GUID?
When the component is developed and globally used, it uses a so-called unique unique identification line UUID to uniquely identify the component. In COM, UUID refers to the global unique identifier Guid. GUID is divided into three categories of CLSID, IID and Libid.
Author Blog:
http://blog.9cbs.net/callzjy/