OOPortal OOPortal


Basic COM  «Prev  Next»
Lesson 11 QueryInterface guidelines
Objective Examine what the COM specification says about QueryInterface.
The COM specification provides significant detail about QueryInterface. Following is a summary of some of the essential points.

Values returned

All interfaces within an instance of a COM object must always return the same value for IUnknown. The reason for this is that the IUnknown pointer is used to identify an instance of a COM object uniquely. In the previous lesson, when asked for IUnknown, we returned a pointer to the first interface in the object IMyComInterface.
The COM specification does not dictate what pointer values should be returned for other interfaces. A client can call QueryInterface and ask for IID_IMyComInterface twice. The object's implementation can choose to return the same IMyComInterface pointer or create a new instance of IMyComInterface for each request. In this example, because we are using multiple inheritance of classes with pure virtual functions, we always return the same pointer value.

Symetric, reflexive, and transitive

QueryInterface is symmetric, reflexive, and transitive.
These requirements are intended to enforce the idea that once a client has an interface pointer into an object, it can navigate to any other interface within the object.

Query Interface - Quiz

Click the Quiz link below to check your understanding of QueryInterface.
Query Interface - Quiz