SUMMARY
When creating an ATL EXE project using the AppWizard, the MFC support check box is disabled. This article explains how to add MFC support to an ATL EXE project. This article also explains how to add MFC support to an ATL DLL project if you failed to initially select the "support MFC" check box in the AppWizard.
MORE INFORMATION
Adding MFC Support to an ATL EXE Project
1. | Add the following #include directives to StdAfx.h prior to including Atlbase.h:
|
2. | Change project settings to use MFC. From the Project Settings dialog box, click the General tab, and change the setting in the "Microsoft Foundation Classes" list box to MFC. |
3. | Add a CWinApp derived class and declare a global variable of that type as follows:
|
4. | Replace the _tWinMain function with the following InitInstance and ExitInstance code:
|
5. | For Unicode builds, make sure the entry point is set to wWinMainCRTStartup in the Output category of the Link field in the Project Settings dialog box. For additional information, please see the following article in the Microsoft Knowledge Base:
125750 PRB: Error LNK2001: '_WinMain@16': Unresolved External Symbol
|
6. | Add the following line of code to the beginning of every member function of a COM interface, window procedure, and exported function: For more information on AFX_MANAGE_STATE, consult the VC++ online documentation.
|
181505 PRB: ATL COM AppWizard Doesn't Offer MFC Support for .EXE
Adding MFC Support to an ATL DLL Project
Follow steps 1 to 3 from above.1. | Move the code in the AppWizard-generated DllMain's DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH to the CMyApp's InitInstance and ExitInstance and remove the DllMain as follows:
|
2. | Add the following line of code to the beginning of every member function of a COM interface, window procedure and exported function: For additional information, please see the following article in the Microsoft Knowledge Base:
140850 How To Converting DLLTRACE to Use MFC in Shared Library
|
When adding a class derived from a MFC class using the ClassWizard to an ATL EXE project or to an ATL DLL project without "MFC Support," the compiler will issue a C2504 error.
REFERENCES
MFCATL Sample included with Visual C++ 5.0.
For additional information, please see the following article in the Microsoft Knowledge Base:
For additional information, please see the following article in the Microsoft Knowledge Base:
186212 How To Unregister MFC Automation Servers
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Chuck Bell, Microsoft Corporation.
APPLIES TO
• | Microsoft ActiveX Template Library 2.0, when used with: | ||||||||||
|
|||||||||||
• | Microsoft ActiveX Template Library 2.1, when used with: | ||||||||||
|
|||||||||||
• | Microsoft ActiveX Template Library 3.0, when used with: | ||||||||||
|
Keywords: |
kbhowto kbfaq KB173974 |