Basic COM  «Prev  Next»

QueryInterface - Quiz Results

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. When asked for IUnknown, an object's implementation of QueryInterface can:
Please select the best answer.
  A. Return any COM interface to the caller because all COM interfaces implement IUnknown
  B. Return E_NOINTERFACE
  C. Always return the same interface pointer as its implementation of IUnknown
 
  The correct answer is C.All requests for IUnknown must return the same value.

2. Read the following code carefully. Which of the following are problems with the code?
  Code examplet
    Please select all the correct answers.
  A. if (riid == IID_IMyComInterface || riid == IID_IUnknown)
  B. else if (riid == IID_IYourComInterface)
  C. *ppv = (IMyComInterface *) this;
  D. AddRef--i.e., (*ppv)->AddRef()--is not called.
 

The correct answers are C and D.The cast on line 11 is wrong. It should be (IYourInterface *). The result of using the wrong cast is to return the wrong vtable to the client. Also, AddRef, i.e., (*ppv)->AddRef() is not called.
  Retake - Quiz