Loading the Common Language Runtime into a Process
Before any managed code can be executed, the host must load and initialize the common language runtime (CLR). All hosts start with an unmanaged stub because the runtime is not yet running in the process. The .NET Framework provides a set of unmanaged APIs called the hosting APIs that the host can use to start the runtime. For more information, see Hosting Interfaces.
Hosting methods provided by versions of the .NET Framework before the .NET Framework version 4 are deprecated. We recommend that you use the interfaces introduced by the .NET Framework 4 and discussed in this topic.
A host can load the CLR into a process by using one of the following procedures:
Call the CLRCreateInstance function to get either an ICLRMetaHost or an ICLRMetaHostPolicy interface. The CLRCreateInstance function supersedes all the CorBindTo* functions listed in the .NET Framework 1.1 and 2.0 Hosting Global Static Functions section.
Call the ICLRRuntimeInfo::GetInterface method. Specify CLSID_CLRRuntimeHost for the rclsid parameter and IID_ICLRRuntimeHost for the riid parameter.
The prototype for all these interfaces is located in the Metahost.h file, which is located in the Include directory of the Windows Software Development Kit (SDK). Hosts can use both the ICLRRuntimeInfo and ICLRRuntimeHost interfaces to control which version of the runtime to load and to control the behavior of basic functions such as garbage collection and assembly loading.
Use the ICLRRuntimeHost interface to perform the following actions:
Start the runtime by calling the ICLRRuntimeHost::Start method.
Execute managed code.
Obtain a pointer to the ICLRControl interface (which provides access to the managers that are implemented by the common language runtime), and register a host control object that implements the IHostControl interface. The common language runtime calls the IHostControl interface to determine which managers the host implements.