Can you describe IUKNOWN interface in brief ?

Q

.NET INTERVIEW QUESTIONS - Can you describe IUKNOWN interface in brief ?

✍: Guest

A

Every COM object supports at least one interface, the IUnknown interface. All interfaces are classes derived from the base class IUnknown. Each interface supports methods access data and perform operations transparently to the programmer. For example, IUnknown supports three methods, AddRef, Release(), and QueryInterface(). Suppose that pinterf is a pointer to an IUnknown.
pinterf->AddRef() increments the reference count.
pinterf->Release() decrements the reference count, deleting the object when the reference count reaches zero.
pinterf->QueryInterface( IDesired,
pDesired) checks to see if the current interface (IUnknown) supports another interface, IDesired, creates an instance (via a call to CoCreateInstance()) of the object if the reference count is zero (the object does not yet exist), and then calls pDesired->AddRef() to increment the reference count (where pDesired is a pointer to IDesired) and returns the pointer to the caller.

2010-01-19, 4362👍, 0💬