Each interface defined by the COM must be inherited from iUnknown, why
Two very important features are provided in the IunkNown interface: survival control and interface queries.
The client can only communicate with the COM object via the interface, although the customer program may
Details of the object inside, but it wants to control the existence or not of the object. If the customer has to follow
Continue to operate the object, then it must ensure that the object can always exist in memory; if the customer
The operation of the object has been completed, and the object is not needed, and it must be timely
The object is released to improve the utilization of resources. IUnknown introduces "reference notification" method
Can effectively control the survival cycle of the object.
On the other hand, if a COM object implements multiple interfaces, at the initial moment, customer
The program is unlikely to get the interface pointer of the object, which only has an interface pointer. in case
The client requires other pointers, then how do it adopt the interface pointer? IUKNown is used
The "Interface Query" method completes the jump between the interfaces.
First let's take a look at the definition of IUNKNOWN (IDL)
Interface IUnknown
{
HRESULT QueryInterface ([in] refiid IID, [OUT] void ** PPV);
Ulong AddRef (Void);
Ulong Release (Void);
}
IUnknown includes three member functions: queryinterface, addref, and release.
Function queryinterface is used to query other interface pointers of COM objects, functions addRef and Release
Used to operate the reference count.