How to: create verifiable C++ projects (C++/CLI)

Visual C++ application wizards do not create verifiable projects.

Important

Visual Studio 2015 deprecated and Visual Studio 2017 does not support the /clr:pure and /clr:safe creation of verifiable projects. If you require verifiable code, we recommend you translate your code to C#.

However, if you are using an older version of the Microsoft C++ compiler toolset that supports /clr:pure and /clr:safe, projects can be converted to be verifiable. This topic describes how to set project properties and modify project source files to transform your Visual Studio C++ projects to produce verifiable applications.

Compiler and linker settings

By default, .NET projects use the /clr compiler flag and configure the linker to target x86 hardware. For verifiable code, you must use the /clr:safe flag, and you must instruct the linker to generate MSIL instead of native machine instructions.

To change the compiler and linker settings

  1. Display the project Property Page. For more information, see Set compiler and build properties.

  2. On the General page under the Configuration Properties node, set the Common Language Runtime Support property to Safe MSIL Common Language Runtime Support (/clr:safe).

  3. On the Advanced page under the Linker node, set the CLR Image Type property to Force safe IL image (/CLRIMAGETYPE:SAFE).

Removing native data types

Because native data types are non-verifiable, even if they are not actually used, you must remove all header files containing native types.

Note

The following procedure applies to Windows Forms Application (.NET) and Console Application (.NET) projects.

To remove references to native data types

  1. Comment out everything in the Stdafx.h file.

Configuring an entry point

Because verifiable applications cannot use the C run-time libraries (CRT), they cannot depend on the CRT to call the main function as the standard entry point. This means that you must explicitly provide the name of the function to be called initially to the linker. (In this case, Main() is used instead of main() or _tmain() to indicate a non-CRT entry point, but because the entry point must be specified explicitly, this name is arbitrary.)

Note

The following procedures apply to Console Application (.NET) projects.

To configure an entry point

  1. Change _tmain() to Main() in the project's main .cpp file.

  2. Display the project Property Page. For more information, see Set compiler and build properties.

  3. On the Advanced page under the Linker node, enter Main as the Entry Point property value.

See also