IUnknown Interface

The IUnknown interface enables clients to retrieve pointers to other interfaces on a given object through its QueryInterface method, and it enables clients to manage the lifetime of the object through the IUnknown::AddRef and IUnknown::Release methods. All other Component Object Model (COM) interfaces are inherited, directly or indirectly, from IUnknown. Therefore, the three methods of IUnknown are the first entries in the vtable for every Microsoft® DirectX® Transform interface.

You must implement IUnknown as part of every interface. Use IUnknown methods to switch between interfaces on an object, to add references, and to release objects.

IUnknown Methods

AddRef Increments the reference count for the calling interface on an object.
QueryInterface Retrieves a specified interface pointer from a COM object.
Release Decrements the reference count for the calling interface on an object.

IUnknown::AddRef

IUnknown Interface

Increments the reference count for the calling interface on an object.

Syntax

ULONG AddRef(
    void
);

Return Value

Returns an integer from 1 to n, which is the value of the new reference count. This information is intended to be used for diagnostic purposes only, because, in certain situations, the value might be unstable.

Remarks

This method should be used for every new copy of a pointer to an interface on a given object.

IUnknown::QueryInterface

IUnknown Interface

Retrieves a specified interface pointer from a COM object.

Syntax

HRESULT QueryInterface(
    REFIID iid,
    void **ppvObject
);

Parameters

iid
[in] Interface ID (IID) of the requested interface.
ppvObject
[out] Location of the requested interface pointer. If the interface specified in the IID is not supported by the object, ppvObject is set to NULL.

Return Value

Returns S_OK if the interface is supported, S_FALSE otherwise.

Remarks

This method must use IUnknown::AddRef on the pointer it returns.

IUnknown::Release

IUnknown Interface

Decrements the reference count for the calling interface on an object.

Syntax

ULONG Release(
    void
);

Return Value

Returns the resulting value of the reference count, which is used for diagnostic purposes only. If you need to know that resources have been freed, use an interface with higher-level semantics.

Remarks

If the reference count on the object falls to zero, the object is freed from memory.


Top of Page Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.