Core ATL classes
CComObjectRoot and CComCoClass
ATL uses multiple inheritance. Your COM implementation class multiply inherits from CComObjectRootEx
and CComCoClass
.
For example, following is the declaration of CPhBookObj
:.
class CPhBookObj :
...,
public CComObjectRoot,
public CComCoClass<CPhBook,&CLSID_PhBook>
{ ... };
As stated above, CComObjectRoot
provides an internal implementation of IUnknown
.
ATL's class hierarchy supports single and multithreaded COM objects. CComObjectRoot
is actually a typedef
of class
CComObjectRootEx
, a template-based class that takes a thread model class as its parameter.
CComObjectRoot
defines a version of CComObjectRootEx
that uses the default threading model.
CComCoClass
is also a template-based class. It provides a data-driven implementation of IClassFactory
.
As template parameters, it takes the name of the C++ class that implements a COM object and the CLSID of the COM object. Using this information, its implementation of
CreateInstance
can instantiate an instance of our C++ class.