COM programming - Study Notes

C ++ and COM object communication method

1, when calling COM DLL COM does not need to do anything special work;
2, COM EXE server on a method call, however, the program is not in the actual process immediately enter the function is called, and the first execution a "proxy" intermediate function: parameter proxy function calls into a serial format standard COM client / server protocol, and then into the EXE COM is connected to the channel; the other end of the channel is called a "pile" of function, "stake" function parameter pack to unlock, truly a call to the requested method; in short, COM communications work for you to do before you have to yourself, for a method that returns a value, and the agent swap stakes action .
3, generation agent and the pile functions: By COM automatically when the CoCreateInstance () to create the object, not only start the corresponding EXE, and returns a pointer to the object and returns a pointer to the proxy function; Thus, according to you create different types of objects, or you get a pointer to the real object, or to obtain a pointer to the proxy function.
4, the proxy function come from? Actually comes from a proxy / stake DLL; CoCreateInstance () to view the system registry Interface () key mapping interface ID to the DLL file name in order to find the required DLL file, then in your "Applications" and "COM EXE server "are loaded this DLL. EXE built COM object class required interface ID according to the request;
COM map the same interface ID to the agent / pile DLL files in the system registry;
COM calls LoadLibrary () on the client and server ends EXE same load DLL;
agent / pile DLL for packaging and unwinding process parameters in a communication network;
5, do not swap memory pointer between applications: process space appear in the program data pointer (char * p), in point of fact, not a real physical memory address, but an application for CPU time assigned to a program into memory the logical address. Because if your CPU to the procedure specified by the physical address, then when the program in memory may be swapped out and say meaningless, you should transfer data directly when passing data between applications instead of passing a pointer.
6, COM term; the COM DLL as "in process", COM EXE become the "in-process"; COM EXE performed in the other system; the COM EXE performed in the local system, known as the "local server" called "remote server"; when using COM access remote COM EXE, COM actually uses a distributed technology (DCOM), instead of the normal COM technology.

How to destroy a COM object
1, the object itself maintains a reference counter;
2, COM will automatically clean your COM object; Whenever you create a pointer to a COM object, object reference count is incremented; whenever a client run COM object , object reference count by 1; when the reference count reaches zero, the COM DLL is unloaded or termination EXE; the COM server EXE automatic monitoring of whether the client is still activate it, if the client application is deadlock, the reference count is automatically Save 1; Marshalling COM data agent / stakes or COM DLL calls the parameters of the method is converted into NDR format (network data Representation); COM RPC call to the formatted data to the server side COM agent / stakes or COM DLL; server side COM agent / COM DLL stakes or reduced to the parameter table data, or put the call stack pointer is opened parameter memory; proxy server side COM / COM DLL or stakes, and then call a method of a COM server;

Reproduced in: https: //www.cnblogs.com/shelvenn/archive/2007/12/24/1012889.html

Guess you like

Origin blog.csdn.net/weixin_33919950/article/details/94184479