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
Display the project Property Page. For more information, see Set compiler and build properties.
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).
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
- 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
Change _tmain() to Main() in the project's main .cpp file.
Display the project Property Page. For more information, see Set compiler and build properties.
On the Advanced page under the Linker node, enter
Main
as the Entry Point property value.