Microsoft DirectX 8.0 |
Declaration: Combase.h
DECLARE_IUNKNOWN Declares the three methods of the base interface for a new interface. GetInterface Retrieves an interface pointer to the requested client. INonDelegatingUnknown Nondelegating version of the IUnknown interface. LoadOLEAut32 Loads the Automation DLL (OleAut32.dll).
Declares the three methods of the base interface for a new interface.
Syntax
#define DECLARE_IUNKNOWN \ STDMETHODIMP QueryInterface(REFIID riid, void **ppv) { \ return GetOwner()->QueryInterface(riid,ppv); \ }; \ STDMETHODIMP_(ULONG) AddRef() { \ return GetOwner()->AddRef(); \ }; \ STDMETHODIMP_(ULONG) Release() { \ return GetOwner()->Release(); \ };
Remarks
When you create a new interface, it must derive from IUnknown, which has three methods: QueryInterface, AddRef, and Release. This macro simplifies the declaration process by declaring each of these methods for the new interface.
Retrieves an interface pointer.
Syntax
HRESULT GetInterface( LPUNKNOWN pUnk, void **ppv );
Parameters
- pUnk
- Pointer to the IUnknown interface.
- ppv
- Address of a pointer to the retrieved interface.
Return Value
Returns an HRESULT value.
Remarks
This member function performs a thread-safe increment of the reference count. To retrieve the interface and add a reference, call this function from your overriding implementation of the INonDelegatingUnknown::NonDelegatingQueryInterface method.
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.
Syntax
interface INonDelegatingUnknown { virtual HRESULT NonDelegatingQueryInterface) (REFIID riid, LPVOID *ppv) PURE; virtual ULONG NonDelegatingAddRef)(void) PURE; virtual ULONG NonDelegatingRelease)(void) PURE; };
Remarks
To use INonDelegatingUnknown for multiple inheritance, perform the following steps.
- Derive your class from an interface, for example, IMyInterface.
- Include DECLARE_IUNKNOWN in your class definition to declare implementations of QueryInterface, AddRef, and Release that call the outer unknown.
- Override NonDelegatingQueryInterface to expose IMyInterface with code such as the following:
if (riid == IID_IMyInterface) { return GetInterface((IMyInterface *) this, ppv); } else { return CUnknown::NonDelegatingQueryInterface(riid, ppv); }- Declare and implement the member functions of IMyInterface.
To use INonDelegatingUnknown for nested interfaces, perform the following steps:
- Declare a class derived from CUnknown.
- Include DECLARE_IUNKNOWN in your class definition.
- Override NonDelegatingQueryInterface to expose IMyInterface with the code such as the following:
if (riid == IID_IMyInterface) { return GetInterface((IMyInterface *) this, ppv); } else { return CUnknown::NonDelegatingQueryInterface(riid, ppv); }- Implement the member functions of IMyInterface. Use CUnknown::GetOwner to access the COM object class.
- In your COM object class, make the nested class a friend of the COM object class, and declare an instance of the nested class as a member of the COM object class.
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.
- Override the NonDelegatingQueryInterface with code such as the following:
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.
Loads the Automation dynamic-link library (OleAut32.dll).
Syntax
HINSTANCE LoadOLEAut32( );
Return Value
Returns a handle to an Automation DLL instance.
Remarks
When the CBaseObject destructor destroys the object that loaded OleAut32.dll, it will unload the library if it is still loaded.