How to: Compile MFC and ATL Code with /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 with /clr
Open the Project Properties dialog by right clicking the project in the Solution Explorer and selecting Properties.
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).
From the same pane, make sure 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 Debug Information Format is set to Program Database /Zi (not /ZI).
Under Configuration Properties, select C/C++ and then Code Generation. Make sure Runtime Library is set to one of Multi-threaded Debug DLL (/MDd) or Multi-threaded DLL (/MD).
To compile an MFC extension DLL with /clr
Follow the steps above in the section "To compile an MFC executable or regular DLL with /clr".
Do one of the following:
Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.
From the Solution Explorer, right click on the file stdafx.cpp and select 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 containing DllMain and anything it calls, open the Property Pages for that file by right clicking the file from the Solution Explorer and selecting 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 with /clr
Open the Project Properties dialog by right clicking the project in the Solution Explorer and selecting Properties.
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 Debug Information Format is set to Program Database /Zi (not /ZI).
Under Configuration Properties, select C/C++ and then Code Generation. Make sure Runtime Library is set to one of Multi-threaded Debug DLL (/MDd) or Multi-threaded DLL (/MD).
For every MIDL generated file (C files), right click the file in the Solution Explorer and select 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 with /clr
Follow the steps above in the section "To compile an ATL executable with /clr".
Do one of the following:
Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.
From the Solution Explorer, right click on the file stdafx.cpp and select 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 containing DllMain and anything it calls, open the Property Pages for that file by right clicking the file from the Solution Explorer and selecting 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.