Microsoft DirectX 8.0

CUnknown Class

CUnknown class hierarchy

Implements the IUnknown interface. Most Component Object Model (COM) objects in Microsoft® DirectShow® derive from CUnknown.

Declaration: Combase.h

If you implement a COM object, you might want to derive it from CUnknown. Deriving from CUknown provides a thread-safe implementation, and saves you the trouble of implementing IUnknown.

For a detailed discussion of how to use this base class, see How to Implement IUnknown. What follows is a brief summary:

Protected Member Variables
m_cRefReference count.
Public Methods
CUnknownConstructor method.
~CUnknownDestructor method. Virtual.
GetOwner Retrieves a pointer to the controlling IUnknown.
INonDelegatingUnknown Methods
NonDelegatingAddRefIncrements the reference count.
NonDelegatingQueryInterfaceRetrieves an interface pointer and increments the reference count.
NonDelegatingReleaseDecrements the reference count.

CUnknown.m_cRef

CUnknown Class

Reference count.

Syntax

volatile LONG m_cRef;

Remarks

Use this member variable if you override the NonDelegatingAddRef or NonDelegatingRelease method.

CUnknown::CUnknown

CUnknown Class

Constructor method.

Syntax

CUnknown(
    const TCHAR *pName,
    LPUNKNOWN pUnk
);

Parameters

pName
String containing the name of the object; used in the CBaseObject constructor for debugging.
pUnk
Pointer to the owner of this object. If the object is aggregated, pass a pointer to the aggregating object's IUnknown interface. Otherwise, set this parameter to NULL.

Remarks

The object is initialized with a reference count of zero.

CUnknown::~CUnknown

CUnknown Class

Destructor method.

Syntax

virtual ~CUnknown(void);

CUnknown::GetOwner

CUnknown Class

Retrieves a pointer to the IUnknown interface of the owning component. For an aggregated component, the owner is the outer component. Otherwise, the component owns itself.

Syntax

LPUNKNOWN GetOwner(void);

Return Value

Returns a pointer to the controlling IUnknown interface.

CUnknown::NonDelegatingAddRef

CUnknown Class

Increments the reference count on the object. Implements the INonDelegatingUnknown::NonDelegatingAddRef method.

Syntax

ULONG NonDelegatingAddRef(void);

Return Value

Returns the reference count.

CUnknown::NonDelegatingQueryInterface

CUnknown Class

Retrieves an interface pointer and increments the reference count. Implements the INonDelegatingUnknown::NonDelegatingQueryInterface method.

Syntax

HRESULT NonDelegatingQueryInterface(
    REFIID riid,
    void **ppv
);

Parameters

riid
Identifier of the interface.
ppv
Address of a pointer to receive the interface.

Return Value

Returns one of the HRESULT values shown in the following table.
S_OKSuccess.
E_NOINTERFACEObject does not support this interface.
E_POINTERNULL pointer argument.

Remarks

The CUnknown class exposes only the IUknown interface. Override this method to expose additional interfaces. For information on how to override this method, see How to Implement IUnknown.

CUnknown::NonDelegatingRelease

CUnknown Class

Decrements the reference count on the object. Implements the INonDelegatingUnknown::NonDelegatingRelease method.

Syntax

ULONG NonDelegatingRelease(void);

Return Value

Returns the reference count.

Remarks

When the reference count reaches zero, the object deletes itself.