CComCoClass

template< class T, const CLSID* pclsid >
class CComCoClass

Parameters

T Your class, derived from CComCoClass.

pclsid A pointer to the CLSID of the object.

CComCoClass provides methods for retrieving an object’s CLSID and setting error information. Any class object that can be created externally should be derived from CComCoClass.

CComCoClass also defines the default class factory and aggregation model for your object. CComCoClass uses the following two macros:

You can override either of these defaults by specifying another macro in your class definition. For example, to use CComClassFactory2 instead of CComClassFactory, specify the DECLARE_CLASSFACTORY2 macro:

class CMyClass : ..., 
   public CComCoClass<CMyClass, &CLSID_CMyClass>
{
public:
   DECLARE_CLASSFACTORY2(CMyLicense)

   ...
};

#include <atlcom.h>


CComCoClass Class Members

Methods
ErrorReturns rich error information to the client.
GetObjectCLSIDReturns the object's class identifier.
GetObjectDescriptionOverride to return the object’s description.

CComCoClass Overview


Methods


CComCoClass::Error

static HRESULT Error( LPCOLESTR lpszDesc, const IID& iid = GUID_NULL, HRESULT hRes = 0 );

static HRESULT Error( LPCOLESTR lpszDesc, DWORD dwHelpID, LPCOLESTR lpszHelpFile, const IID& iid = GUID_NULL, HRESULT hRes = 0 );

static HRESULT Error( LPCSTR lpszDesc, const IID& iid = GUID_NULL, HRESULT hRes = 0 );

static HRESULT Error( LPCSTR lpszDesc, DWORD dwHelpID, LPCSTR lpszHelpFile, const IID& iid =

static HRESULT Error( UINT nID, const IID& iid = GUID_NULL, HRESULT hRes = 0, HINSTANCE hInst = _Module.GetResourceInstance( ) );

static HRESULT Error( UINT nID, DWORD dwHelpID, LPCOLESTR lpszHelpFile, const IID& iid = GUID_NULL, HRESULT hRes = 0, HINSTANCE hInst = _Module.GetResourceInstance( ) );

Return Value

A standard HRESULT value. For details, see Remarks.

Parameters

lpszDesc [in] The string describing the error. The Unicode version of Error specifies that lpszDesc is of type LPCOLESTR; the ANSI version specifies a type of LPCSTR.

iid [in] The IID of the interface defining the error or GUID_NULL (the default value) if the error is defined by the operating system.

hRes [in] The HRESULT you want returned to the caller. The default value is 0. For more details about hRes, see Remarks.

nID [in] The resource identifier where the error description string is stored. This value should lie between 0x0200 and 0xFFFF, inclusively. In debug builds, an ASSERT will result if nID does not index a valid string. In release builds, the error description string will be set to “Unknown Error.”

dwHelpID [in] The help context identifier for the error.

lpszHelpFile [in] The path and name of the help file describing the error.

hInst [in] The handle to the resource. By default, this parameter is _Module::GetResourceInstance, where _Module is the global instance of CComModule or a class derived from it.

Remarks

This static method sets up the IErrorInfo interface to provide error information to the client. In order to call Error, your object must implement the ISupportErrorInfo interface.

If the hRes parameter is nonzero, then Error returns the value of hRes. If hRes is zero, then the first four versions of Error return DISP_E_EXCEPTION. The last two versions return the result of the macro MAKE_HRESULT( 1, FACILITY_ITF, nID ).

CComCoClass Overview | Class Members

See Also ISupportErrorInfoImpl, MAKE_HRESULT and IErrorInfo in the Win32 SDK


CComCoClass::GetObjectCLSID

static const CLSID& GetObjectCLSID( );

Return Value

The object's class identifier.

Remarks

Provides a consistent way of retrieving the object's CLSID.

CComCoClass Overview | Class Members


CComCoClass::GetObjectDescription

static LPCTSTR WINAPI GetObjectDescription( );

Return Value

The class object’s description.

Remarks

This static method retrieves the text description for your class object. The default implementation returns NULL. You can override this method with the DECLARE_OBJECT_DESCRIPTION macro. For example:

class CMyClass : public CComCoClass< ... >, ...
{
public:
   DECLARE_OBJECT_DESCRIPTION("Account Transfer Object 1.0") 
   ...
};

GetObjectDescription is called by IComponentRegistrar::GetComponents. IComponentRegistrar is an Automation interface that allows you to register and unregister individual components in a DLL. When you create a Component Registrar object with the ATL Object Wizard, the wizard will automatically implement the IComponentRegistrar interface. IComponentRegistrar is typically used by Microsoft Transaction Server.

For more information about the ATL Object Wizard, see the article Creating an ATL Project.

CComCoClass Overview | Class Members