How to: Compile MFC and ATL Code By Using /clr
The latest version of this topic can be found at How to: Compile MFC and ATL Code By Using -clr.
This topic discusses how to compile existing MFC and ATL programs to target the Common Language Runtime.
To compile an MFC executable or regular DLL by using /clr
Right-click the project in Solution Explorer and then click Properties.
In the Project Properties dialog box, expand the node next to Configuration Properties and select General. In the right pane, under Project Defaults, set Common Language Runtime support to Common Language Runtime Support (/clr).
In the same pane, make sure that Use of MFC is set to Use MFC in a Shared DLL.
Under Configuration Properties, expand the node next to C/C++ and select General. Make sure that Debug Information Format is set to Program Database /Zi (not /ZI).
Select the Code Generation node. Set Enable Minimal Rebuild to No (/Gm-). Also set Basic Runtime Checks to Default.
Under Configuration Properties, select C/C++ and then Code Generation. Make sure that Runtime Library is set to either Multi-threaded Debug DLL (/MDd) or Multi-threaded DLL (/MD).
In Stdafx.h, add the following line.
#using <System.Windows.Forms.dll>
To compile an MFC extension DLL by using /clr
Follow the steps in "To compile an MFC executable or regular DLL by using /clr".
Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.
As an alternative, in Solution Explorer, right-click Stdafx.cpp and then click Properties. Under Configuration Properties, expand the node next to C/C++ and select General. Set Compile with Common Language Runtime support to No Common Language Runtime support.
For the file that contains DllMain and anything it calls, in Solution Explorer, right-click the file and then click Properties. Under Configuration Properties, expand the node next to C/C++ and select General. In the right pane, under Project Defaults, set Compile with Common Language Runtime support to No Common Language Runtime support.
To compile an ATL executable by using /clr
In Solution Explorer, right-click the project and then click Properties.
In the Project Properties dialog box, expand the node next to Configuration Properties and select General. In the right pane, under Project Defaults, set Common Language Runtime support to Common Language Runtime Support (/clr).
Under Configuration Properties, expand the node next to C/C++ and select General. Make sure that Debug Information Format is set to Program Database /Zi (not /ZI).
Select the Code Generation node. Set Enable Minimal Rebuild to No (/Gm-). Also set Basic Runtime Checks to Default.
Under Configuration Properties, select C/C++ and then Code Generation. Make sure that Runtime Library is set to either Multi-threaded Debug DLL (/MDd) or Multi-threaded DLL (/MD).
For every MIDL-generated file (C files), right-click the file in Solution Explorer and then click Properties. Under Configuration Properties, expand the node next to C/C++ and select General. Set Compile with Common Language Runtime support to No Common Language Runtime support.
To compile an ATL DLL by using /clr
Follow the steps in the "To compile an ATL executable by using /clr" section.
Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.
As an alternative, in Solution Explorer, right-click Stdafx.cpp and then click Properties. Under Configuration Properties, expand the node next to C/C++ and select General. Set Compile with Common Language Runtime support to No Common Language Runtime support.
For the file that contains DllMain and anything it calls, in Solution Explorer, right-click the file and then click Properties. Under Configuration Properties, expand the node next to C/C++ and select General. In the right pane, under Project Defaults, set Compile with Common Language Runtime support to No Common Language Runtime support.