## Further Reading

Accessing COM
  A section in the Microsoft® DirectX® 5 documentation, under the heading "Introducing DirectX 5," within the topic "DirectX and the Component Object Model." This topic describes how COM implements DirectX objects and interfaces.
IUnknown Interface
  All COM interfaces are derived from the IUnknown interface. This interface provides control of the object's lifetime and the ability to navigate multiple interfaces. IUnknown has three methods: AddRef, which increments the object's reference count by 1 when an interface or another application binds itself to the object; QueryInterface, which queries the object about the features it supports by requesting pointers to a specific interface; and Release, which decrements the object's reference count by 1. When the count reaches 0, the object is deallocated. See also AddRef and QueryInterface
IUnknown::AddRef and IUnknown::Release
  These IUnknown methods maintain an object's reference count. For example, if you create a DirectPlay object (with CoCreateInstance, for example), 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. You must 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.
IUnknown::QueryInterface
  This IUnknown method determines whether an object supports a specific interface. If an object supports the interface, QueryInterface returns a pointer to that interface. You then can use the methods contained in 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.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.