Compiler COM Support Classes

Microsoft Specific

Standard classes are used to support some of the COM types. The classes are defined in COMDEF.H and the header files generated from the type library.

#include <comdef.h>

Class Purpose
_com_error Defines the error object thrown by _com_raise_error in most failures.
_com_ptr_t Encapsulates COM interface pointers, and automates the required calls to AddRef, Release, and QueryInterface.
_bstr_t Wraps the BSTR type to provide useful operators and methods.
_variant_t Wraps the VARIANT type to provide useful operators and methods.

In addition, there is a support routine called _com_raise_error, which is used by all compiler-generated COM support code to throw a _com_error in response to a failure

_com_raise_error is defined in comdef.h as,

void __stdcall _com_raise_error(HRESULT hr, IErrorInfo* perrinfo = 0) throw(_com_error);

The actual source code is,

void __stdcall _com_raise_error(HRESULT hr, IErrorInfo* perrinfo) throw(_com_error)
{
  throw _com_error(hr, perrinfo);
}

_com_raise_error can be replaced by a user-written version of the same name and prototype. This could be done if you want to use #import, but don't want to use C++ exception handling. In that case, a user version of _com_raise_error might decide to do a longjmp or pop up a message box and halt. The user version should not return, though, since the compiler COM support code does not expect it to return.

END Microsoft Specific