IUnknown

From Wikipedia, the free encyclopedia

The published COM specification mandates that COM objects must minimally implement the IUnknown interface. This interface comprises three functions - QueryInterface, AddRef and Release.

  • QueryInterface is used to obtain a pointer to another interface, given a GUID that uniquely identifies that interface (commonly known as an IID). If the COM object does not implement that interface, an error is returned instead.
  • AddRef is used by clients to indicate that a COM object is being referenced. This is necessary to ensure that a COM object is not disposed prematurely
  • Release is used by clients to indicate that they have finished using the COM object. An unreferenced COM object may be safely disposed.


interface IUnknown
{
  virtual ULONG AddRef(void) = 0; 
  virtual HRESULT QueryInterface(REFIID riid, void **ppvObject) = 0;
  virtual ULONG Release(void) = 0; 
};


The IUnknown interface is defined as a GUID with the value of {00000000-0000-0000-C0000-00000000046}.

[edit] Miscellanea

[edit] See also