fbpx
Wikipedia

IUnknown

In computer programming, the IUnknown interface is the fundamental interface in the Component Object Model (COM). The COM specification[1] mandates that COM objects must 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 object functionality through other interfaces.

An IUnknown (or IUnknown-derived) 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 order that they are declared in the interface. The in-process invocation call overhead is therefore identical to virtual method calls in C++.[2]

Methods edit

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

  • QueryInterface allows the caller to retrieve references to the interfaces that the component implements. It is similar to dynamic_cast<> in C++ or casts in Java and C#. Specifically, it is used to obtain a pointer to another interface, given a GUID that uniquely identifies that interface (commonly known as an interface ID, or IID). If the COM object does not implement that interface, an E_NOINTERFACE error is returned instead.
  • AddRef is used to increment the reference count when a new client is acquiring the object. It returns the new reference count.
  • Release is used to decrement the reference count when clients have finished using the object. It returns the new reference count. The object will delete itself during release when the reference-count reaches zero, which means that the caller must never use an interface after calling Release.
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 edit

  • Components designed under the ActiveX visual component standard must, at a minimum, implement the IUnknown interface.[4]
  • IUnknown serves as the base for Mac OS X's Core Foundation CFPlugIn framework.[5]
  • In Mozilla's XPCOM component model, this interface is also known as nsISupports.

See also edit

References edit

  1. ^ , archived from the original on 2004-02-15
  2. ^ "The Component Object Model". microsoft.com. Microsoft. 30 May 2018. Retrieved 12 February 2019.
  3. ^ IUnknown definition at microsoft.com 2013-07-11 at the Wayback Machine; accessed 18-Jan-2008
  4. ^ ActiveX Controls at microsoft.com; accessed 18-Jan-2008
  5. ^ Plug-ins at apple.com; accessed 18-Sept-2011

External links edit

  • COM in plain C

iunknown, computer, programming, interface, fundamental, interface, component, object, model, specification, mandates, that, objects, must, implement, this, interface, furthermore, every, other, interface, must, derived, from, exposes, essential, features, obj. In computer programming the IUnknown interface is the fundamental interface in the Component Object Model COM The COM specification 1 mandates that COM objects must 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 object functionality through other interfaces An IUnknown or IUnknown derived 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 order that they are declared in the interface The in process invocation call overhead is therefore identical to virtual method calls in C 2 Contents 1 Methods 2 Miscellaneous 3 See also 4 References 5 External linksMethods editThe IUnknown interface exposes three methods QueryInterface AddRef and Release 3 QueryInterface allows the caller to retrieve references to the interfaces that the component implements It is similar to a href Dynamic cast html class mw redirect title Dynamic cast dynamic cast a lt gt in C or casts in Java and C Specifically it is used to obtain a pointer to another interface given a GUID that uniquely identifies that interface commonly known as an interface ID or IID If the COM object does not implement that interface an E NOINTERFACE error is returned instead AddRef is used to increment the reference count when a new client is acquiring the object It returns the new reference count Release is used to decrement the reference count when clients have finished using the object It returns the new reference count The object will delete itself during release when the reference count reaches zero which means that the caller must never use an interface after calling Release 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 editComponents designed under the ActiveX visual component standard must at a minimum implement the IUnknown interface 4 IUnknown serves as the base for Mac OS X s Core Foundation CFPlugIn framework 5 In Mozilla s XPCOM component model this interface is also known as nsISupports See also editIOleObject This is the base interface for Object Linking and Embedding OLE objects IDispatch This interface provides name based dynamic method dispatch for OLE Automation COM objects IObjectWithSite This COM interface allows a parent child pair of objects to connect to each other to implement a Browser Helper Object BHO IInspectable The COM derived Windows Runtime WinRT uses this IUnknown derived interface as its base interfaceReferences edit The Component Object Model Specification archived from the original on 2004 02 15 The Component Object Model microsoft com Microsoft 30 May 2018 Retrieved 12 February 2019 IUnknown definition at microsoft com Archived 2013 07 11 at the Wayback Machine accessed 18 Jan 2008 ActiveX Controls at microsoft com accessed 18 Jan 2008 Plug ins at apple com accessed 18 Sept 2011External links editCOM in plain C Retrieved from https en wikipedia org w index php title IUnknown amp oldid 1093866324, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.