Microsoft DirectX 8.1 (C++) |
All COM objects support an interface called IUnknown. This interface provides Microsoft® DirectX® with control of the object's lifetime and the ability to retrieve other interfaces implemented by the object. IUnknown has three methods.
The AddRef and Release methods maintain an object's reference count. For example, if you create a Microsoft Direct3D® object, the object's reference count is set to 1. Every time a function returns a pointer to an interface for that object, the function must call AddRef through that pointer to increment the reference count. Match each AddRef call with a call to Release. Before the pointer can be destroyed, you must call Release through that pointer. After an object's reference count reaches 0, the object is destroyed, and all interfaces to it become invalid.
The QueryInterface method determines whether an object supports a specific interface. If an object supports an interface, QueryInterface returns a pointer to that interface. You then can use the methods of that interface to communicate with the object. If QueryInterface successfully returns a pointer to an interface, it implicitly calls AddRef to increment the reference count, so your application must call Release to decrement the reference count before destroying the pointer to the interface.
Windows NT/2000/XP: Requires Windows NT 3.1 or later.
Windows 98/Me: Requires Windows 98 or later.
Header: Declared in Unknwn.h.