Basic COM  «Prev 

IUnknown and interface navigation

Implementation of QueryInterface
Implementation of QueryInterface


Lines 4 and 5: Checks to see if the caller (usually the client) is asking for a pointer to IMyComInterface or IUnknown. All COM interfaces must support navigation to IUnknown as well as all other interfaces within the object. If a match is found, the ppv output parameter is assigned to the this pointer using a cast to (IMyComInterface *).
Line 9: Checks to see if the caller wants an interface pointer to IYourComInterface. If a match is found, the ppv output parameter is assigned to the this pointer with a cast to (IYourComInterface *).
Line 13: Returns error code E_NOINTERFACE to tell the caller that the COM object does not implement the requested interface.
Line 15: Calls AddRef through the previously assigned ppv output parameter. This is a requirement! In COM, every time we provide an interface pointer to a caller, we must increment its reference count. Lesson 12 discusses AddRef, Release, and reference counting in more detail.
Line 16: Returns S_OK to indicate a successful call.