Edit

Share via


Converting projects from mixed mode to pure intermediate language

All Visual C++ CLR projects link to the C run-time libraries by default. As a result, these projects are classified as mixed-mode applications, because they combine native code with code that targets the common language runtime (managed code). When they're compiled, they get compiled into intermediate language (IL), also known as Microsoft intermediate language (MSIL).

Important

Visual Studio 2015 deprecated and Visual Studio 2017 no longer supports the creation of /clr:pure or /clr:safe code for CLR applications. If you require pure or safe assemblies, we recommend you translate your application to C#.

If you're using an earlier version of the Microsoft C++ compiler toolset that supports /clr:pure or /clr:safe, you can use this procedure to convert your code to pure MSIL:

To convert your mixed-mode application into pure intermediate language

  1. Remove links to the C runtime libraries (CRT):

    1. In the .cpp file defining the entry point of your application, change the entry point to Main(). Using Main() indicates that your project doesn't link to the CRT.

    2. In Solution Explorer, right-click your project and select Properties on the shortcut menu to open the property pages for your application.

    3. In the Advanced project property page for the Linker, select the Entry Point and then enter Main in this field.

    4. For console applications, in the System project property page for the Linker, select the SubSystem field and change it to Console (/SUBSYSTEM:CONSOLE).

      Note

      You don't have to set this property for Windows Forms applications because the SubSystem field is set to Windows (/SUBSYSTEM:WINDOWS) by default.

    5. In stdafx.h, comment out all the #include statements. For example, in console applications:

      // #include <iostream>
      // #include <tchar.h>
      

      -or-

      For example, in Windows Forms applications:

      // #include <stdlib.h>
      // #include <malloc.h>
      // #include <memory.h>
      // #include <tchar.h>
      
    6. For Windows Forms applications, in Form1.cpp, comment out the #include statement that references windows.h. For example:

      // #include <windows.h>
      
  2. Add the following code to stdafx.h:

    #ifndef __FLTUSED__
    #define __FLTUSED__
       extern "C" __declspec(selectany) int _fltused=1;
    #endif
    
  3. Remove all unmanaged types:

    Wherever appropriate, replace unmanaged types with references to structures from the System namespace. Common managed types are listed in the following table:

    Structure Description
    Boolean Represents a Boolean value.
    Byte Represents an 8-bit unsigned integer.
    Char Represents a Unicode character.
    DateTime Represents an instant in time, typically expressed as a date and time of day.
    Decimal Represents a decimal number.
    Double Represents a double-precision floating-point number.
    Guid Represents a globally unique identifier (GUID).
    Int16 Represents a 16-bit signed integer.
    Int32 Represents a 32-bit signed integer.
    Int64 Represents a 64-bit signed integer.
    IntPtr A platform-specific type that is used to represent a pointer or a handle.
    SByte Represents an 8-bit signed integer.
    Single Represents a single-precision floating-point number.
    TimeSpan Represents a time interval.
    UInt16 Represents a 16-bit unsigned integer.
    UInt32 Represents a 32-bit unsigned integer.
    UInt64 Represents a 64-bit unsigned integer.
    UIntPtr A platform-specific type that is used to represent a pointer or a handle.
    Void Indicates a method that doesn't return a value; that is, the method has the void return type.