Поделиться через


How to: Create a Partially Trusted Application by Removing Dependency on the CRT Library DLL

This topic discusses how to create a partially trusted Common Language Runtime application using Visual C++ by removing dependency on msvcm90.dll.

A Visual C++ application built with /clr will have a dependency on msvcm90.dll, which is part of the C-Runtime Library. When you want your application to be used in a partial trust environment, the CLR will enforce certain code access security rules on your DLL. Therefore, it will be necessary to remove this dependency because msvcm90.dll contains native code and code access security policy cannot be enforced on it.

If your application does not use any functionality of the C-Runtime Library and you would like to remove the dependency on this library from your code, you will have to use the /NODEFAULTLIB:msvcmrt.lib linker option and link with either ptrustm.lib or ptrustmd.lib. These libraries contain object files for initialization and uninitialization of an application, exception classes used by the initialization code, and managed exception handling code. Linking in one of these libraries will remove any dependency on msvcm90.dll.

Note

The order of assembly uninitialization might differ for applications that use the ptrust libraries. For normal applications, assemblies are usually unloaded in the reverse order that they are loaded, but this is not guaranteed. For partial trust applications, assemblies are usually unloaded in the same order that they are loaded. This, also, is not guaranteed.

To create a partially trusted mixed (/clr) application

  1. To remove the dependency on msvcm90.dll, you must specify to the linker not to include this library by using the /NODEFAULTLIB:msvcmrt.lib linker option. For information on how to do this using the Visual Studio development environment or programmatically, see /NODEFAULTLIB (Ignore Libraries).

  2. Add one of the ptrustm libraries to the linker input dependencies. Use ptrustm.lib if you are building your application in release mode. For debug mode, use ptrustmd.lib. For information on how to do this using the Visual Studio development environment or programmatically, see .Lib Files as Linker Input.

See Also

Reference

/link (Pass Options to Linker)

Concepts

Mixed (Native and Managed) Assemblies

Initialization of Mixed Assemblies

Library Support for Mixed Assemblies

Other Resources

Security in Native and .NET Framework Code