Basic COM  «Prev  Next»
Lesson 13The client's view of IUnknown
Objective Explain how the client views IUnknown.

Client's View of IUnknown

To help us understand COM's interface navigation and reference-counting mechanisms better, we need to examine the client's perspective. The following pseudo-code demonstrates client-side logic that uses MyComObject. For now, we need to defer the details of how we initialize a COM object and get our first interface pointer into it.
  1. The declaration of an HRESULT. This is used to hold the return value of COM calls
  2. Here MyComObject is initialized and we get an interface pointer to interface IMyComObject. We will cover the details of how this is done in the next module.
  3. A call is made to IMyComInterface::Fx2.
  4. A check is made on the return value from Fx2. FAILED is a standard COM error checking macro.
  5. This declares a variable as a pointer to COM interface IYourComInterface.
  6. IMyComInterface::QueryInterface is called to get a pointer to IYourComInterface.
  7. If the QueryInterface call is successful, this calls IYourComInterface::Zx1.
  8. The FAILED macro is used to check the status of the previous COM call.
  9. This calls IMyComInterface::Release.
  10. This calls IYourComInterface::Release. Interface pointers held by a client should be considered invalid after calling Release.

Client View of Iunknown

Reference Counting - Exercise

Click the Exercise link below to apply what you have learned about reference counting.
Reference Counting - Exercise