IUnknown Interface

Like all Component Object Model (COM) interfaces, the IDirectSound and IDirectSoundBuffer interfaces also include the AddRef, Release, and QueryInterface methods. The AddRef method increases the reference count of the object and the Release method decreases the reference count. Your applications can use the QueryInterface method to determine what additional interfaces an object supports.

When an object is created, its reference count is set to 1. Each time a new application binds to the object or a previously bound application binds to a different interface of the object, the reference count is increased by 1. Each time an application is released from an interface, the reference count is decreased by 1. The object deallocates itself when its reference count goes to 0. The Release method notifies the object that an application is no longer bound to the object.

Your application can use the QueryInterface method to ask an object if it supports a particular interface. If the interface is supported, it can be used immediately. If the interface is not needed, you must call the Release method to free it. QueryInterface allows objects to be extended by Microsoft and third parties without breaking or interfering with each other's existing or future functionality.

Note DirectSoundBuffer objects are owned by the DirectSound object that created them. When the DirectSound object is released, all buffers created by that object will be released as well and should not be referenced.