One, COM is a better C + +
1, COM is what
Don box says "COM is Love". The full name of COM is the Component object model.
2. From C + + to DLL to COM
2.1 C + +
If a software vendor publishes a class library (Cmath arithmetic), the executable code of the class library becomes an integral part of the customer application. Suppose that the generated machine code for this class library occupies 4MB of space in the target executable file. When three applications use the Cmath library, each executable contains a 4MB class library code (see Figure 1.1). When three applications are running together, they will consume 12MB of virtual memory. The problem is far from it. Once a class library vendor discovers a flaw in the Cmath class library, it publishes a new class library that requires all applications that use such libraries. Besides, there is no other way.
Figure 1.1 Cmath Three customers
2.2 DLL
One technique for solving the above problem is to encapsulate the Cmath class in the form of a dynamic-link library (DLL, Dynamics link).
When using this technique, all cmath methods will be added to the Cmath DLL's extraction table (export list), and the linker will produce an import library. This library exposes the symbols of the Cmath method members. When the customer chain comes into the warehouse, some stubs are introduced into the executable file, which notifies the loader to dynamically load the Cmath Dll at run time.
When Cmath is in a DLL, his running model is shown in Figure 1.2
Figure 1.2 Cmath Introduction to the Warehouse
2.3 COM
"Simply drawing the C + + class definition out of the DLL" does not provide a reasonable binary component structure. Because the C + + class is both an interface and an implementation. This requires separating the interface from the implementation to provide a binary component structure. At this point, you need two C + + classes, one as the interface class and the other as the implementation class. Let's start with the COM tour.