ATL Development   «Prev 

Inside ATL-generated code

The ATL COM AppWizard generates a global instance of CComModule and the required in-process server functions. For this project, this code is in file PhBook.cpp. Following are excerpts from this file.

...
CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance,
  DWORD dwReason, LPVOID /*lpReserved*/)
  
{
    ...
}

Essential COM
STDAPI DllCanUnloadNow(void)
{
    return (_Module.GetLockCount()==0)
   ? S_OK : S_FALSE;   
}
STDAPI DllGetClassObject(REFCLSID rclsid,
  REFIID riid, LPVOID* ppv)  
{
    return _Module.GetClassObject(rclsid, riid, ppv);
}

STDAPI DllRegisterServer(void)
{
    // registers object, typelib and
    all interfaces in typelib
    
    return _Module.RegisterServer(TRUE);
}

STDAPI DllUnregisterServer(void)
{
    return _Module.UnregisterServer(TRUE);
}

Notice how each DLL function makes a call into _Module.
BEGIN_OBJECT_MAP and END_OBJECT_MAP are macros. These are used to add a server's COM objects into the ATL framework. We will revisit object maps in the next lesson.