Difficulty: Easy
Correct Answer: IUnknown is the base COM interface that all COM objects must implement, and its three methods are QueryInterface, AddRef, and Release
Explanation:
Introduction / Context:
In Microsoft Component Object Model (COM), IUnknown is the fundamental interface from which all other COM interfaces derive. Understanding IUnknown is essential for anyone working with COM, ActiveX, or older Windows component technologies. This question asks you to identify what IUnknown represents and to name its three core methods. It checks your knowledge of COM basics, including interface discovery and reference counting for object lifetime management.
Given Data / Assumptions:
Concept / Approach:
IUnknown is the base interface defined by COM and is required for all COM objects. It provides three methods: QueryInterface, AddRef, and Release. QueryInterface allows a client to request pointers to different interfaces that the object supports, enabling interface discovery and polymorphism. AddRef and Release implement reference counting. AddRef increments the object reference count when a new client uses the interface, and Release decrements it when a client is finished. When the reference count reaches zero, the COM object can safely destroy itself. These three methods together support the core COM goals of binary compatibility, dynamic interface discovery, and deterministic lifetime management.
Step-by-Step Solution:
Step 1: Identify that the question is specifically about COM and IUnknown, not about printing, networking, or graphics APIs.
Step 2: Recall that IUnknown is the root interface in COM, and that all other interfaces such as IDispatch, IDataObject, and custom interfaces derive from it.
Step 3: List the three IUnknown methods by name: QueryInterface, AddRef, and Release.
Step 4: Recognize that QueryInterface is used to obtain pointers to supported interfaces, while AddRef and Release maintain a reference count for object lifetime.
Step 5: Select the option that correctly describes IUnknown as the base COM interface and correctly names all three methods.
Verification / Alternative check:
Examining COM documentation or example code clearly shows that interface definitions begin with IUnknown methods. A typical interface might be declared as including the three IUnknown methods followed by additional interface specific methods. Developers calling COM objects typically use pInterface->AddRef and pInterface->Release to manage lifetime and pInterface->QueryInterface to request other interfaces. This confirms that the correct answer must mention these exact methods and not unrelated method names from other subsystems.
Why Other Options Are Wrong:
Option B is wrong because IUnknown is not a printing API, and PrintPage, PausePrint, and CancelPrint are not standard COM interface methods. Option C incorrectly treats IUnknown as a network protocol interface, which it is not. Option D is misleading because database operations use other APIs and not this COM base interface. Option E confuses IUnknown with a graphics library; drawing functions like DrawLine and DrawCircle belong to other libraries, not to COM core interfaces.
Common Pitfalls:
A common pitfall is to forget that COM is designed around binary compatible interfaces and reference counting; misunderstanding IUnknown leads to memory leaks or crashes due to incorrect reference management. Another issue is confusing QueryInterface with language level casting; in COM, you must use QueryInterface instead of a C++ cast to obtain other interfaces. Remembering the trio QueryInterface, AddRef, Release and their roles is crucial for safe COM programming.
Final Answer:
In COM, IUnknown is the base interface that all COM objects must implement, and it defines three methods: QueryInterface for interface discovery, AddRef for incrementing the reference count, and Release for decrementing the reference count and freeing the object when it is no longer in use.
Discussion & Comments