COM COM first talk

zhaozj2021-02-16  49

COM first talk

First, please see the following questions:

l What is CoM?

l What is a COM object?

l What is an interface?

Let's talk about the first one, COM full name is Compon Object Model. He is a set of specifications, a set of binary and network standards created by Microsoft, which is used to solve communication between two components, which can be said to Microsoft. Almost all strategies are built on it. From 1993, CoM was first launched, he did destined to the fate of Microsoft's development ...

What is a COM object?

COM is an object-oriented software model, the concept of COM object is a bit similar to the concept of objects in C . In the COM specification, there is no strict definition of COM objects, and the COM component is provided to the customer, and the entity that is encapsulated in the form of objects, and the entity interacting with the component is a COM object.

The COM object has its own properties and methods, but these are encapsulated by the COM. The customer can only call the COM method only through the interface. The interface is the only way for COM and external communication, interaction.

What is an interface?

It has been said above, the interface is the only way to communicate with the outside world. His definition is the core of the COM specification. The interface is a collection of logical related functions, which can be seen as a pointer to the reorganization function.

The following figure shows the relationship between the interface and the COM object:

As can be seen from the above figure, a COM component is mainly composed of two parts, a part is the definition of the interface, and the other is the implementation of the COM object, and the definition of the interface in the COM specification is relatively independent.

The definition of the interface - the definition of the interface follows MIDL, he is Microsoft extension in the IDL language specification for OSF DCE (Distributes Computing Environment) specification. As can be seen from the above figure, the interface is a data structure containing a set of functions, and he is only responsible for defining a function. After the object is created, he is an interface pointer and a virtual function table. The interface pointer points to the virtual function table (the function table has become a set of function pointers), each function pointer points to the corresponding "COM object implementation" Implementation of functions. Interface specifications are not built on any programming language, any language with sufficient data expressions, can be described.

COM object implementation - implementation code for all functions of all interfaces of COM objects.

COM overall model

The application established according to COM specification is based on a Client / Server model. A complete COM application includes the following parts: COM server, server COM library, customer COM library, client program.

A brief description of each part first:

COM server - is a container, this container is used to install all COM objects

Server COM Library - It can be seen as a manager of a container, responsible for identifying the corresponding COM object from the container, created

An instance of an object.

Customer COM Library - Connector, responsible for transmitting customer requests to the service party, responsible for customer COM control management

Customer program - the enjoyment of COM service.

A complete method call includes the following steps:

1. The customer program notifies the COM library, pointing to the GUID or IID of the COM object he wants to call;

2. The client COM library accepts customer requirements, sending this request to the server, and establishing the generation of the COM object within the customer process.

After the DLL (in later customers interact with the agent DLL).

3. Server COM library accepts requests, finds the COM object from the COM library, establish an instance of the COM object (component into

Cheng), when an instance is established, a stub DLL is created in the process of the instance. The component program interacts with the client's stub DLL via the stub DLL.

4. The client program calls the proxy DLL interface method;

5. Agent DLL puts the request interface, method, parameters, data, packages (Marshalling); send to the stub DLL;

6. The stub DLL receives a data packet from a proxy DLL, a distribution (unmarshalling); sent to the component program;

7. Component program processing data, returns to the stub DLL;

8. Save the root DLL column (MARSHALLING), sent to the agent DLL;

9. The agent DLL returns the result to the client.

[Note: For the stub and the agent, please pay attention to follow-up]

Creation of COM object

How is the COM library creates a COM object?

Through the class factory, the class is a production base for the COM object, and each COM object has a corresponding class. The class is also a COM object, he supports an interface iClassFactory, the function creteInstance (...) for constructing an instance of the COM object.

The process of creating a COM:

1. The customer gives the COM library Guid;

2. The COM library calls the COGETCLASSObject (...) function to get the COM object class, create a COM object.

CocreateInstance (...) functions, also creating the object by invoking the CogetherClassObject (...) function inside it, create an object.

Temporarily here, everyone, old brothers, old sishers, if they find incorrectly, or different perspectives, but also point out, discuss, together!

转载请注明原文地址:https://www.9cbs.com/read-26957.html

New Post(0)