Com learning records

Source: Internet
Author: User

COM component program: module, which can be a dynamic connection library (DLL) & executable program (exe), called in-process component) & External process component (out-of-process component ).

COM Object: it is based on binary executable code. Therefore, COM objects are language-independent. This feature makes it possible to interact with Component Objects developed using different programming languages.

Com standard: Standard & implementation. Standard: defines the communication mechanism between components, and does not rely on specific languages and operating systems. Implementation: The com Library and the com library provide some core services for the specific implementation of the COM standard. The implementation includes some core system-level code, which enables interaction between objects and customers at the binary code level through interfaces.

Tag object: each object is identified by a 128-bit guid, which is called CLSID (Class Identifier, Class Identifier or class ID). It can be ensured that the object is identified by clsid (probability) global uniqueness. As long as the system contains information about such COM objects & including the module files (DLL or EXE files) of the COM Object & COM object in the code entry point, the client program can create a COM object through the CLSID.

Flag interface: In the com model, the object itself is visible to the customer, and the customer can only request the service through the interface. Each interface is identified by a 128-bit GUID (guid, globally unique identifier). The user obtains the interface pointer through the guid and calls the corresponding member function through the interface pointer.

Service: After the customer successfully creates an object, it obtains a pointer to an interface of the object. Because the COM Object implements at least one interface, the customer can call all services provided by this interface.

  

Com Library: generally not implemented at the application layer, but at the operating system level. Therefore, an operating system only has one com library, in addition, the implementation of the COM library must depend on the specific system platform, especially the underlying standards of the system. The library ensures that all components interact in a uniform manner, so that when writing a com application, we can not write a lot of Basic Code necessary for COM Communication, by directly using the APIS provided by the COM library for programming, the development speed is accelerated.

COM Object Features: encapsulation & reusability & polymorphism. However, such polymorphism can only be reflected through the interface of the COM object, just as the polymorphism of the C ++ object can be reflected through its (virtual) function.

COM interface specification: An Interface contains the data structure of a group of functions. These group of functions are all information exposed by component objects, the Customer Code can call the functions of component objects. The client calls the interface member function by a pointer to the interface data organization. The interface pointer actually points to another pointer. The second Pointer Points to a group of functions, called the interface function table (virtual function table ), each item in the interface function table is a four-byte function pointer, which is connected with the specific implementation of the Object. As long as the user obtains the interface pointer, he can call the actual functions of the object. For an interface, its virtual function table vtable is determined, so the number of member functions of the interface is unchanged, and the sequence of member functions is also unchanged; for each member function, its parameters and return values are also determined.

Interface Description Language: How to describe interfaces? The description language of the COM interface is IDL. The description language of the IDL Interface can be used to define not only COM interfaces, but also common data types and custom data structures. For interface member functions, we can specify the type of each parameter, input and output features, and even support the description of variable length arrays. IDL supports pointer types, similar to C/C ++. Microsoft Visual C ++ provides the midl tool to compile the IDL Interface Description file into a C/C ++-compatible interface description header file (. h), so that the interface described by a strange Dongdong IDL can be converted to the C ++ form:

Iunknown definition (IDL): interface iunknown {hresult QueryInterface ([in] refiid IID, [out] void ** GMM); ulong addref (void ); ulong release (void);} iunknown definition (C ++): Class iunknown {public: Virtual hresult _ stdcall QueryInterface ([in] refiid IID, [out] void ** GMM) = 0; virtual ulong _ stdcall addref (void) = 0; virtual ulong _ stdcall release (void) = 0 ;}

Iunknown is an interface. All com interfaces inherit iunknown. Defined in the unknwn header file of Win32 SDK.

QueryInterface is a member function of iunknown. You can use this function to query whether a component supports a specific interface and return a pointer to the interface supported by the component, if the interface supported by the component is not found, null is returned.

In-process components: The in-process components and the customer program run in the same process address space. Once the customer Program establishes a communication relationship with the component program, the interface pointer obtained by the client program points to the vtable of the interface in the component program. This vtable contains all the member function addresses. The customer code can directly call these member functions, so the efficiency is very high. The DLL program is loaded into the memory by the customer at runtime, so the DLL module itself is also independent and does not depend on the customer program.

Operation DLL program: There are three system functions, loadlibrary & getprocaddress & freelibrary. Generally, the use of DLL programs follows these steps:

First, the client program uses the loadlibrary function to load the DLL. This function returns the instance handle of the module for future operations on this module. Then, the client program can call the getprocaddress function to obtain the address of the function derived from the DLL, which can be specified by the function serial number (in the def file) you can also obtain the address of the function according to the function name. Because the client program and DLL program are in the same memory address space, the client program can directly call these function. Finally, freelibrary unloads the DLL program out of memory to release resources.

COM components are not: COM components are not DLL, com only uses DLL to provide dynamic links to components; COM components are not an API function set; COM components are not classes

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.