Most ATL classes are template based. ATL is shipped as a set of source files. To use ATL classes, we include ATL's *.h and *.cpp files
in our project. For basic ATL projects, the core files we use are atlbase.h and atlcom.h. ATL files can be found in the Visual C++ ATL\include and ATL\src directories.
ATL provides built-in support for COM servers, class factories, and
IUnknown
. The general idea behind using ATL is to plug
your application classes into the ATL class hierarchy. You add one C++ class for each COM object in a server. Following are brief summaries of ATL core classes.
ATL class
CComModule
provides support for COM server functionality. It provides methods to register and unregister COM objects,
check server lock and references counts, and get class objects. All ATL-based programs have a global instance of
CComModule
(or a class derived from it) called
_Module
.
Class
CComObject
provides
QueryInterface
,
AddRef
, and
Release
. These methods call into internal methods in
CComObjectRoot
.
Class
CComObjectRoot
(and its base class,
CComObjectRootBase
) provides an internal data-driven implementation of
IUnknown
, called from
QueryInterface
,
AddRef
, and
Release
in
CComObject
.
Class
CComCoClass
provides a data-driven implementation of
IClassFactory
.
An interesting feature of ATL is that your application classes are not the most derived classes! An instance of
CComObject derives from your class.
Normally, we do not manually code required in-process server functions (for example, DllGetClassObject
) or our COM object implementation classes.
Instead, we use the ATL COM AppWizard to generate a skeleton server and add our COM implementation classes using Visual C++ tools. This is the topic of the next lesson.