A preliminary study of COM technology (1)

Source: Internet
Author: User
Tags class definition object model requires cmath

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.