Udostępnij za pośrednictwem


Changing the Default Class Factory and Aggregation Model

ATL uses CComCoClass to define the default class factory and aggregation model for your object. CComCoClass specifies 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 ATL_NO_VTABLE CMyClass2 :
   public CComObjectRootEx<CComSingleThreadModel>,
   public CComCoClass<CMyClass2, &CLSID_MyClass>,
   public IDispatchImpl<IMyClass, &IID_IMyClass, &LIBID_NVC_ATL_COMLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
   public IDispatchImpl<IMyDualInterface, &__uuidof(IMyDualInterface), &LIBID_NVC_ATL_COMLib, /* wMajor = */ 1, /* wMinor = */ 0>
{
public:
   DECLARE_CLASSFACTORY2(CMyLicense)

   // Remainder of class declaration omitted

Two other macros that define a class factory are DECLARE_CLASSFACTORY_AUTO_THREAD and DECLARE_CLASSFACTORY_SINGLETON.

ATL also uses the typedef mechanism to implement default behavior. For example, the DECLARE_AGGREGATABLE macro uses typedef to define a type called _CreatorClass, which is then referenced throughout ATL. Note that in a derived class, a typedef using the same name as the base class's typedef results in ATL using your definition and overriding the default behavior.

See Also

Reference

Fundamentals of ATL COM Objects

Other Resources

Aggregation and Class Factory Macros