COM, component object model, popular saying is COM, providing a programming architecture. The COM components should be implemented through the COM specification
Some interfaces and interface functions, other programs use these functions by fixed methods, under the Windows platform, so-called fixed methods are provided
Various GUIDs found COM components in the registry, then call the specified DLL or EXE (via ROT) to call the specified function to get the required
The pointer of the interface, the pointer to the so-called interface is actually pointing to the pointer of the function pointer, and the service provided by the COM component is called through the interface pointer.
If you do not use the ATL and other class libraries, it is also very simple, just keep in mind the following points:
1. Use the IDL to define the interface in the IDL file. Because COM is independent of language, it is necessary to define a language that can be understood by various languages.
interface. Compiling the MIDL to compile a good IDL file to get a .h file, you can see it in the IDL file from this file.
The interface is compiled into a pure virtual class in C . From here you can get:
A. The memory structure of the pure empty class is indeed the same as the memory requirements required for COM, so use a pure virtual class to define a COM interface;
B. In fact, you can use the C language to define the COM interface directly without the IDL file. Why do you need it? Simply speaking, it is for
Realize the language independence of COM. The interface that uses C defined cannot be used by other languages, when using the IDL file written in the IDL language
After being compiled by MIDL, you can generate a .tlb type library file, this file can be used by other languages.
2. The implementation of the interface is actually very simple, that is, it can be implemented in the derived class of the defined interface. A derived class can inherit
From multiple interfaces. In order to achieve some features, you can inherit from some standard COM interfaces, such as Idispatch, Imarshl, etc., but general
You need to implement iClassFactory or iClassFactory2 interface. The role of a class factory interface is to provide a generally created component object
method. For process components in C we can use New to create new objects, but for processes or remote components, New
It seems that it is impossible, so providing a class factory interface, dealing with the class and proxy to complete the creation of the object.
3. Implement the relevant export function in the component program to be called, such as registration functions, lifecycle control functions, and more.
4, in mind, if you want to see more than MSDN, you can read some common standard interfaces, pay special attention to the suite, column sets.
Whether using nested classes in the MFC to implement COM, or multiple inherits used in ATL to implement COM, or use ODL language to write
The definition of the interface, it is basically above, but only some macro in the MFC and ATL replace the various types of definitions written directly using C ,
The function definition, etc., make the program look simple, but for the principle of knowing COM, it is not good, so see when using these macros.
Their definition will help you understand COM more deeply. The ODL language is just an expansion of the IDL language. In fact, there is nothing special place, just look at it,
I can understand some keywords, such as Interface, Dispinterface, Coclass, Import, Library,
Importlib, Defult, etc.
In short, you have to know COM, skilled use of COM programming, as Don said, more mobile phone programming, use them, and consider them
How work is working.