INonDelegatingUnknown::INonDelegatingUnknown

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);

Remarks

To use INonDelegatingUnknown for multiple inheritance, perform the following steps:

  1. Derive your class from an interface, for example, IMyInterface.

  2. Include DECLARE_IUNKNOWN in your class definition to declare implementations of QueryInterface, AddRef, and Release that call the outer unknown.

  3. 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);
         }
    
  4. Declare and implement the member functions of IMyInterface.

To use INonDelegatingUnknown for nested interfaces, perform the following steps:

  1. Declare a class derived from CUnknown.

  2. Include DECLARE_IUNKNOWN in your class definition.

  3. 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);
         }
    
  4. Implement the member functions of IMyInterface. Use CUnknown::GetOwner to access the COM object class.

  5. 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 cannot 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.

Requirements

DirectShow applications and DirectShow filters have different include file and link library requirements. See Setting Up the Build Environment for more information.

OS Versions: Windows CE 2.12 and later. Version 2.12 requires DXPAK 1.0 or later.

See Also

INonDelegatingUnknown Interface

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.