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