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.
Com Interface
Line 1:The declaration of an HRESULT. This is used to hold the return value of COM calls.
Lines 2 and 3: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.
Line 4:A call is made to IMyComInterface::Fx2.
Line 5:A check is made on the return value from Fx2. FAILED is a standard COM error checking macro.
Lines 7:This declares a variable as a pointer to COM interface IYourComInterface.
Lines 9 and 10:IMyComInterface::QueryInterface is called to get a pointer to IYourComInterface.
Line 13:If the QueryInterface call is successful, this calls IYourComInterface::Zx1.
Line 14:The FAILED macro is used to check the status of the previous COM call.
Line 16:This calls IMyComInterface::Release.
Line 17:This calls IYourComInterface::Release. Interface pointers held by a client should be considered invalid after calling Release.


Reference Counting - Exercise

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