To enable a class to support both nondelegating and delegating IUnknown interfaces in the same COM object, the Combase.h header file declares the INonDelegatingUnknown interface. This interface is a version of IUnknown and has three methods:
INonDelegatingUnknown::NonDelegatingQueryInterface |
INonDelegatingUnknown::NonDelegatingAddRef |
INonDelegatingUnknown::NonDelegatingRelease |
For sample implementations of these methods, see CUnknown::NonDelegatingQueryInterface, CUnknown::NonDelegatingAddRef, and CUnknown::NonDelegatingRelease.
A version of IUnknown renamed to enable a class to support both nondelegating and delegating IUnknown interfaces in the same COM object. The interface supports the following three methods, in vtable order:
HRESULT NonDelegatingQueryInterface(
REFIID iid,
void** ppvObject );
ULONG NonDelegatingAddRef(void);
ULONG NonDelegatingRelease(void);
To use INonDelegatingUnknown for multiple inheritance, perform the following steps:
if (riid == IID_IMyInterface) { return GetInterface((IMyInterface *) this, ppv); } else { return CUnknown::NonDelegatingQueryInterface(riid, ppv); }
To use INonDelegatingUnknown for nested interfaces, perform the following steps:
if (riid == IID_IMyInterface) { return GetInterface((IMyInterface *) this, ppv); } else { return CUnknown::NonDelegatingQueryInterface(riid, ppv); }
Because you must always pass the outer unknown and an HRESULT to the CUnknown constructor, you can't use a default constructor. You have to make the member variable a pointer to the class and make a new call in your constructor to actually create it.
if (riid == IID_IMyInterface) { return m_pImplFilter-> NonDelegatingQueryInterface(IID_IMyInterface, ppv); } else { return CUnknown::NonDelegatingQueryInterface(riid, ppv); }
You can have mixed classes that support some interfaces through multiple inheritance and some interfaces through nested classes.
GetInterface, CUnknown, IUnknown Macro
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.