Summary
ATL provides a layered approach to implementing
IUnknown. The top layer, represented by the
CComXxxThreadModel classes, provides helper functions and
type definitions for synchronization required of both STAs and
MTAs. The second level, CComObjectRootEx, uses the
threading model classes to support "just thread-safe enough"
AddRef and Release implementations and
object-level locking. CComObject-RootEx also provides a
table-driven implementation of QueryInterface, using an
interface map provided by your class. Your class derives from
CComObjectRootEx and any number of interfaces, providing
the interface member function implementations. The final level is
provided by CComObject and friends, which provide the
implementation of QueryInterface, AddRef, and
Release based on the lifetime and identity requirements of
the object.
To allow each class to define its one lifetime
and identity requirements, each class defines its own
_CreatorClass, which defines the appropriate Creator. The
Creator is responsible for properly creating an instance of your
ATL-base class and should be used in place of the C++ operator
new.
Finally, to debug your objects, ATL provides a
number of debugging facilities, including tracing and interface
usage and leak tracking.
|