OOPortal OOPortal


ATL Development   «Prev  Next»
Lesson 6 Examining ATL code
Objective Understand object maps and COM maps.

Examining ATL Code

Using Visual C++ tools to add class CPhBookObj and interfaces IReadPhBook and IManagePhBook adds code and new files into our project. Class View should now show entries for both interfaces and CPhBookObj.
Class View
Class View

Adding COM object PhBookObj to the project added an entry to the object map in PhBook.cpp, our server implementation file.
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_PhBookObj, CPhBookObj)
END_OBJECT_MAP()

Each COM object within a server is bound into the ATL framework by adding it into the object map using the OBJECT_ENTRY macro. The OBJECT_ENTRY macro takes the object's CLSID and the name of the implementation class as parameters. This identifies a specific C++ class as implementing a COM object.
Each COM object implementation class contains a COM map:
class CPhBookObj : ... {
...
BEGIN_COM_MAP(CPhBookObj)
COM_INTERFACE_ENTRY(IReadPhBook)
COM_INTERFACE_ENTRY(IManagePhBook)
END_COM_MAP()
...
};

Each interface implemented by an object has a COM_INTERFACE_ENTRY macro.
COM maps add methods and data into the class used by the ATL framework to manage each interface.
ATL-based COM classes use multiple inheritance. Each class inherits from each interface it implements. Each of these interface classes is really an interface specification, for example, a class with all pure virtual methods. We previously discussed CComObjectRoot and CComCoClass.
COM implementation class CPhBookObj is defined in header file PhBookObj.h as follows:

class CPhBookObj : 
 public IReadPhBook,
 public IManagePhBook,
 public CComObjectRoot,
 public CComCoClass <CPhBookObj,&CLSID_PhBookObj>
{
public:
 CPhBookObj() {}
BEGIN_COM_MAP(CPhBookObj)
 COM_INTERFACE_ENTRY(IReadPhBook)
 COM_INTERFACE_ENTRY(IManagePhBook)
END_COM_MAP()


DECLARE_REGISTRY_RESOURCEID(IDR_PhBookObj)

public:
};

Macro DECLARE_REGISTRY_RESOURCEID will be discussed in the next lesson.

ATL Com Objects - Quiz

Click the Quiz link below to check your understanding of ATL COM objects.
ATL Com Objects - Quiz