Monday, January 18, 2016
COM Fundamentals
COM requires that the only way to gain access to the methods of an interface is through a pointer to the interface. An interface definition specifies the interface's member functions, called methods, their return types, the number and types of their parameters, and what they must do. There is no implementation associated with an interface.
COM interfaces are immutable—You cannot define a new version of an old interface and give it the same identifier. Adding or removing methods of an interface or changing semantics creates a new interface, not a new version of an old interface. Therefore, a new interface cannot conflict with an old interface. However, objects can support multiple interfaces simultaneously and can expose interfaces that are successive revisions of an interface, with different identifiers. Thus, each interface is a separate contract, and systemwide objects need not be concerned about whether the version of the interface they are calling is the one they expect. The interface ID (IID) defines the interface contract explicitly and uniquely.
All COM objects must implement the IUnknown interface。
For any given object instance, a call to QueryInterface(IID_IUnknown, ...) must always return the same physical pointer value(((IUnknown*)*ppv)->AddRef(); ). This allows you to call QueryInterface(IID_IUnknown, ...) on any two interfaces and compare the results to determine whether they point to the same instance of an object.
Containment/Delegation(包容/托管) the outer object explicitly delegates implementation to the inner object's methods,That is, the outer object uses the inner object's services to implement itself.显然所有com对象都支持包容。
Aggregation is actually a specialized case of containment/delegation.the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself.
The following rules apply to creating an aggregable object:
The aggregable (or inner) object's implementation of QueryInterface, AddRef, and Release for its IUnknown interface controls the inner object's reference count, and this implementation must not delegate to the outer object's unknown (the controlling IUnknown).
The aggregable (or inner) object's implementation of QueryInterface, AddRef, and Release for its other interfaces must delegate to the controlling IUnknown and must not directly affect the inner object's reference count.
The inner IUnknown must implement QueryInterface only for the inner object.
The aggregable object must not call AddRef when holding a reference to the controlling IUnknown pointer.
When the object is created, if any interface other than IUnknown is requested, the creation must fail with E_NOINTERFACE.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment