COM objects and interfaces

zhaozj2021-02-16  50

Com objects and interfaces

An object implements an interface, what he means is that the object uses code to implement each method of the interface.

And for these functions to provide a COM library with a binary pointer. The COM then makes these functions

Request a client pointing to the interface.

Interfaces and interface IMPLEMENTATIONS

COM has a fundamentally differentiated definition and implementation of the interface. An interface is actually a group that defines usage

Contact functional prototypes, just he can't be implemented. These function prototypes are equivalent to the base class with a pure virtual function in C . An interface definition has developed a member function of the interface, a call method, a return type, and the number and type of their parameters, these functions should do. But here is not related to the interface. The implementation of an interface is the code that the programmer executes the relevant action provided on an excuse definition.

The implementation of an interface is the code that the programmer executes the relevant action provided on an excuse definition. Customer call is entirely determined by the interface.

Interface Pointers and Interfaces

An instance of the interface implementation is actually a pointer to a group of methods, ie, pointing to a function table of an interface, which references the implementation of all methods of the interface.

Each interface is a set of fixed sets of methods, locating through the Global Unique Interface Identifier (IID) at runtime. Here, IID is a special instance of Globally Unique Identifier (GUID) supported by COM. Don't produce the same name on a single system, conflicts between multiple versions of the interface.

A COM interface is different from the C class;

A COM interface is not an object - he is just a simple associated group of functions, which is a binary standard for communication between customers and programs. As long as he provides a pointer to the excuse method, this object can use any language to implement him. ;

COM interface top top top top Type top 10 - Each interface has his own excuse identifier;

· The invariance of the COM interface - you cannot define a new version with an old version of the interface identifier, the interface contract of the interface IID definition is clear, unique.

Iunknown and interface inheritance

Inheriting does not mean the reuse of the code in COM. Because the interface does not achieve association, the excuse is inherited and the code is inherited. What he means is merely, an interface is associated, just like the creation and modification of the pure virtual base class of C , add a method or further reinforcement method. There is no selective inheritance in COM. If an interface is inherited by another interface, he contains all the methods defined by another interface.

USING AND IUNKNOWN

COM provides a rich standard collection for internal communications of objects and objects. For details on the implementation and use of the iUnknown interface, see the topic below: Queryinterface: Navigating in an Object.

Rules for Implementing QueryInterface

Manage the three main rules of the iUnknown :: queryinterface method for implementing a COM object:

1. Objects must have an identifier;

2. An interface collection of an object instance must be static;

3. Query this interface from any other interface in the object is successful.

Manage the life cycle of objects by reference to counting

Add reference to addRef () //

Realase () // Reduce reference

转载请注明原文地址:https://www.9cbs.com/read-26959.html

New Post(0)