IUnknown

In computer programming, the IUnknown (custom) interface is the fundamental interface in the Component Object Model (COM). The published COM specification mandates that COM objects must minimally implement this interface. Furthermore, every other COM interface must be derived from IUnknown. IUnknown exposes two essential features of all COM objects: object lifetime management through reference counting, and access to various predefined interfaces.

A custom IUnknown interface consists of a pointer to a virtual method table that contains a list of pointers to the functions that implement the functions declared in the interface, in the same order that they are declared in the interface. The in-process invocation overhead is therefore comparable to virtual method calls in C++.

Methods

The IUnknown interface exposes three methods: QueryInterface, AddRef, and Release:[1]

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

The IUnknown interface ID is defined as a GUID with the value of {00000000-0000-0000-C000-000000000046}.

A COM component's interfaces are required to exhibit the reflexive, symmetric, and transitive properties. The reflexive property refers to the ability for the QueryInterface call on a given interface with the interface's ID to return the same instance of the interface. The symmetric property requires that when interface B is retrieved from interface A via QueryInterface, interface A is retrievable from interface B as well. The transitive property requires that if interface B is obtainable from interface A and interface C is obtainable from interface B, then interface C should be retrievable from interface A.

Miscellaneous

See also

References

  1. IUnknown definition at microsoft.com; accessed 18-Jan-2008
  2. ActiveX Controls at microsoft.com; accessed 18-Jan-2008
  3. Plug-ins at apple.com; accessed 18-Sept-2011
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.