Share via


Create an ATL Project that supports MFC

When you first create a project based on the Active Template Library (ATL), you can specify that support for the MFC library classes be added to the project.

To include MFC support in an ATL-based project

  1. Start a new ATL COM AppWizard project. (From the File menu, choose New and click the Projects tab, then select the ATL COM AppWizard project type.)

  2. In the ATL COM AppWizard Step 1 dialog box, select the Support MFC checkbox.

  3. This option links your project to the MFC libraries, so that you can access any of the classes and functions they contain. It does so by declaring the application as an MFC application object (class) which can then initialize and clean up the ATL module:

    class CATL_COMApp : public CWinApp
    {
    public:
        virtual BOOL InitInstance();
        virtual int ExitInstance();
    };
    
    CATL_COMApp theApp;
    
    BOOL CATL_COMApp::InitInstance()
    {
        _Module.Init(ObjectMap, m_hInstance, &LIBID_ATL_COMLib);
        return CWinApp::InitInstance();
    }
    
    int CATL_COMApp::ExitInstance()
    {
        _Module.Term();
        return CWinApp::ExitInstance();
    }
    

You can view the application object class and its InitInstance and ExitInstance functions in ClassView.

See Also