Let us discuss more about the unmanaged code portion of the
hosts before we go into the managed portion of code. All hosts must start with
an unmanaged stub. The .NET Framework provides a set of unmanaged API's the
host can use to get the CLR running.
As discussed above, the unmanaged portion of CLR hosts is
responsible for loading the CLR into the process. Hosts use the
CorBingToRunTimeEx API to load the CLR into the process. The CorBingToRunTimeEx
API takes four parameters for loading the CLR. Let us discuss each parameter in
detail. The code shown below is the unmanaged API CorBindToRuntimeHost.
Listing 1
HRESULT CorBindToRuntimeHost (
[in] LPCWSTR pwszVersion,
[in] LPCWSTR pwszBuildFlavor,
[in] LPCWSTR pwszHostConfigFile,
[in] VOID* pReserved,
[in] DWORD startupFlags,
[in] REFCLSID rclsid,
[in] REFIID riid,
[out] LPVOID FAR *ppv
);
·
Version - As shown in Listing 1, the pwszVersion is the parameter
that determines which version of Common Language Runtime is to be loaded.
·
Server versus workstation - As shown in Listing 1, pwszBuildFlavor
specifies whether to load the server or the workstation build of the Common Language
Runtime.
·
Concurrent GC - StartupFlags specifies a set a predifined flags
that control garbage collection.
1.
STARTUP_CONCURRENT_GC - Specifies that concurrent garbage collection
should be used.
·
Loader optimization - Controls whether assemblies are loaded
domain-neutrally. A domain neutral assembly is an assembly that can be shared
by different application domains.
1.
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN - No assemblies are loaded as
domain-neutral. [Except mscorlib] This setting is called single domain because
it is commonly used when the host is running only a single application in the
process.
2.
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN - All assemblies are loaded as
domain-neutral.
3.
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST All strong-named
assemblies are loaded as domain-neutral.