ATL learning Summary

Under the side of the case, COM components would be like this.
ATL_NO_VTABLE cmath class:
   public CComObjectRootEx <CComSingleThreadModel>,
   public CComCoClass, <cmath, & CLSID_Math>,
   public IMath,
   public IAdvancedMath
{
...
}

CMath is defined by the user, but it is actually an abstract class, that is, there must be a class that inherits from CMath. This gives the default class is CCOMObject <CMath>. It provides three interfaces IUnknow, AddRef (), Release () , QueryInterface ().
The reason for using the template, in order not to use the virtual pointer, but realized the function polymorphism.
CMath inherited from CComCoClass, which encapsulates a series of registration on the registry, get a job class factory interface.
Look at the definition of CComCoClass.
Template <class T, pClsid = const * & CLSID_NULL the CLSID>
class CComCoClass,
{
public:
    DECLARE_CLASSFACTORY ()
    DECLARE_AGGREGATABLE (T)
    typedef T _CoClass;
...
}
defined in DECLARE_CLASSFACTORY.
DECLARE_CLASSFACTORY #define () \
typedef CComCreator <CComObjectCached <CComClassFactory>> _ClassFactoryCreatorClass;
defined in DECLARE_AGGREGATABLE.
#define DECLARE_AGGREGATABLE (x) public: \
    typedef CComCreator2< CComCreator< CComObject< x > >, CComCreator< CComAggObject< x > > > _CreatorClass;

_ClassFactoryCreatorClass and _CreatorClass two typedef, for
BEGIN_OBJECT_MAP (the ObjectMap)
    OBJECT_ENTRY (CLSID_Math, cmath)
END_OBJECT_MAP ()

These macro generates a table. Elements Element table is CLSID_Math, CMath :: _ ClassFactoryCreatorClass :: CreateInstance , CMath :: _ CreatorClass :: CreateInstance, and so on.
CMath :: _ ClassFactoryCreatorClass :: CreateInstance method for generating corresponding class factory interface.
CMath :: _ CreatorClass :: CreateInstance method for class corresponding to produce an interface.
Using methods such as:
  the IClassFactory pFC * = NULL;
  cmath :: _ :: ClassFactoryCreatorClass the CreateInstance (NULL, IID_IClassFactory, (void **) & pFC);
  IAdvancedMath * P = NULL;
  cmath :: _ :: CreatorClass the CreateInstance (NULL, IID_IAdvancedMath, (void **) & p);
look back _ClassFactoryCreatorClass definition.
CComCreator typedef <CComObjectCached <CComClassFactory>> _ClassFactoryCreatorClass;
CComObjectCached <CComClassFactory> Inherited from CComClassFactory. CComObjectCached functions like CCOMObject. Except that there is a cache mechanism, just for the class factory.
CComCreator a CComObjectCached <CComClassFactory> the CreateInstance method.

Look back _CreatorClass definition.
CComCreator2 typedef <CComCreator <the CComObject <X>>, CComCreator <CComAggObject <X>>> _CreatorClass;
CComCreator2 a non-polymeric or polymeric. When polymerized with CComCreator <CComAggObject <x>>, when using non-polymeric CComCreator <CComObject <x>.

Creating a component

CComObject<CMath>* ptrMath;
CComObject<CMath>::CreateInstance( &ptrMath );
CComPtr<IMath> pMath = ptrMath;

Reproduced in: https: //www.cnblogs.com/fanzi2009/archive/2010/04/19/1715418.html

Guess you like

Origin blog.csdn.net/weixin_33881140/article/details/94192405