Udostępnij za pośrednictwem


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

  1. Open the Project Properties dialog by right clicking the project in the Solution Explorer and selecting Properties.

  2. 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.

  3. 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).

  4. 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

  1. Follow the steps above in the section "To compile an MFC executable or regular DLL with /clr".

  2. Do one of the following:

    1. Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.

    2. 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.

  3. 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

  1. Open the Project Properties dialog by right clicking the project in the Solution Explorer and selecting Properties.

  2. 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).

  3. 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).

  4. 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).

  5. 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

  1. Follow the steps above in the section "To compile an ATL executable with /clr".

  2. Do one of the following:

    1. Under Configuration Properties, expand the node next to C/C++ and select Precompiled Headers. Set Create/Use Precompiled Header to Not using Precompiled Headers.

    2. 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.

  3. 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.

See Also

Concepts

Mixed (Native and Managed) Assemblies