When ATL support is added (using ATL Object Wizard) to an existing MFC executable or DLL, several modifications are made to the existing MFC project. These modifications are as follows (in this example, the project is called MFCEXE
):
InitATL
) is called from the InitInstance function of the application class to initialize ATL. Code is also added to the ExitInstance function for ATL termination. In the header file, support is added to track the attempt to initialize ATL. Finally, two new header files are included (Initguid.h and Mfcexe_i.c) in the implementation file, declaring and initializing the new GUIDs for the CComModule-derived class.CMfcExeModule
) is declared and defined and new files are included (Statreg.h and Atlimpl.h) for static registry of the ATL support.When you add ATL support to an MFC DLL project, you will see some differences. First, a global variable, _Module
, of type CComModule is added. In addition, code is added to the DLLRegisterServer and DLLUnregisterServer functions for registering and unregistering the DLL.
Note The ATL Object Wizard does not add entries to the DEF file for an MFC DLL. You must add these yourself.
If your project is a DLL COM server, you must export four functions by hand. To accomplish this, add the following to the EXPORTS section of your project's .def file:
DllCanUnloadNow @1 PRIVATE
DllGetClassObject @2 PRIVATE
DllRegisterServer @3 PRIVATE
DllUnregisterServer @4 PRIVATE