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. Consequently, 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 are compiled, they are compiled into intermediate language (IL), also known as Microsoft intermediate language (MSIL).

To convert your mixed-mode application into pure intermediate language

  1. Remove links to the C run-time 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 does not 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 this to Console (/SUBSYSTEM:CONSOLE).

      Note

      You do not 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:

    1. 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 does not return a value; that is, the method has the void return type.