The client code described in this lesson builds on the previous lessons on
initializing and uninitializing COM,
class factories,
interface navigation,
reference counting,
in-process servers, and
CoCreateInstance.
COM object Definitions:
Following are definitions for COM object O1 and interfaces IF1 and IF2. These definitions are shared between the client and the server.
The client uses them to get class ids, interface ids, and interface definitions.
To use COM object O1 and interfaces IF1 and IF2, we do the following:
COM clients: Coding a client
Error messages
COM interface and API calls return an HRESULT. Macros FAILED and SUCCEEDED take in an HRESULT and return a Boolean value that can be used to check the return status of a COM method. Win32 API function FormatMessage can take in an HRESULT returned from a COM API call (for example, CoCreateInstance) or a COM interface method and return a string message that provides a short description of the error.
Using FormatMessage
Win32 API function FormatMessage can take in an HRESULT returned from a
COM API call (for example, CoCreateInstance) or a COM interface method and return a string message that provides a short description of the error.
hr = CoCreateInstance(...);
if (FAILED(hr)) {
ComErrorMsg(hr);
...
}
FormatMessage can also handle other (i.e., non-COM) Win32 API calls. Normally, you must call GetLastError to get the error code before calling FormatMessage.
See the Microsoft Platform SDK documentation for more details.
Com ClientCode - Exercise
Click the Exercise link below to apply what you have learned about writing client code. COM Client Code - Exercise