Windows API Reference

IUnknown Interface

The IUnknown interface is the base interface from which all COM (Component Object Model) interfaces are derived. It provides the fundamental mechanisms for reference counting and querying for other interfaces supported by an object.

Every COM object must implement IUnknown. This interface guarantees that you can always discover the identity and capabilities of a COM object.

Methods

Remarks

IUnknown is central to the COM model. Its three methods are fundamental:

  • QueryInterface: Allows clients to ask an object if it supports a particular interface (identified by its GUID, or IID).
  • AddRef: Used to increment the reference count of an object. Clients call this when they obtain a pointer to an interface and want to ensure the object stays alive.
  • Release: Used to decrement the reference count. Clients call this when they are finished with an interface pointer. When the count reaches zero, the object typically destroys itself.

Proper management of reference counts is crucial to prevent memory leaks and dangling pointers in COM programming.

Important: Every COM interface must inherit from IUnknown, directly or indirectly. This ensures that all COM objects support these core functionalities.

See Also