COM is a better C COM designed to develop a reusable binary component, which must be used by all programming languages that support COM standards. C lacks the standard, object-oriented characteristics (including modularity) disappeared after the program is added, and the reusability of the code is lost. Therefore, the object-oriented characteristics of the C code can only be used to use these code prior to each time. For a class library for many customers, the use of the use of the module directly with the use of the module directly, and the complexity of the entire program code is added. COM uses a binary runtime standard on the software industry to improve the development capability of C binary components.
The COM standard is based on DLL technology: Dynamic Link Library. DLL is the beginning of C implementation of binary runtime standard, which will change the two-binary code to replaceable, reusable components. There are many ways to implement a DLL in C , such as:
First, use _Declspec (dllexport) and _Declspec (dllimport). If only two groups of symbols are used, the generated DLL can only be used in C without having to know other sectors. So the first method will use several symbols: extern "c" _declspec (dllexport) int _stdcall myfunction (int N1, int N2); // Export EXTERN "C" _Declspec (dllimport) int MyFunction (int N1, int N2) ; // Import Class_Declspec (DLLEXPORT) MyClass {...} // from another program to export EXTERN "C" to make the sector to finish the function in mode C, this way Make functions cannot be overloaded. Because C is an object-oriented language, it supports the overload of the function, and the sector usually uses Name Mangling (Name Adaptation) to implement the overload of the function. The NM approach is to tamper with the name of the overloaded function according to its own way, and different sectors will have different ways. So if the function we have to be exported is overloaded, we will be difficult to use _Declspec (dllimport) to link the function code in the DLL, because the function in the DLL is tampered with the function name, we don't know what it is. So I can't link it. This case can be reduced using the third method (.def file). However, if you use externaln "C", you can get "link compatibility", and _stdcall makes DLL components to "call compatibility", any language can link and call the function inside it, because almost all languages Standard calls (stdcall) are supported.
Second, use the sector command (more trouble): #pragma comment (Linker, "/ export: myfunction = _myfunction @ 12") #pragma comment (Linker, "/ Import: myfunction = _myfunction @ 12")
Third, use the .def file, which contains a list of program export functions.