CComObject: How ATL creates COM objects
CComObject is the most-derived class; it uses our COM implementation class as a base class. CComObject
is defined as a template that takes the name of our COM implementation class as a parameter.
Following is a partial listing of CComObject
from file atlcom.h:
template <class Base>
class CComObject : public Base
{
public:
...
STDMETHOD_(ULONG, AddRef)(){...}
STDMETHOD_(ULONG, Release)(){...}
...
STDMETHOD(QueryInterface)
(REFIID iid, void ** ppvObject)
{...}
...
};
ATL uses internal creator classes to create COM object classes (i.e., ComCreator
and ComCreator2
in atlcom.h). These classes call another internal creator method. This function creates an instance of our COM object by calling new CComObject()
.
For CPhBookObj
, this call is new CComObject<CPhBookObj>()
.