The Hosting APIs of Common Language Runtime (CLR) provide an easy way to dynamically launch an application written in managed code in the unmanaged world. The topic has been well discussed and is out of the scope of this article.
This article will talk about an issue that you will face when using CLRs Hosting APIs. Suppose you want to write an EXE launcher that can launch executables written in managed and unmanaged codes. It is expected that the launcher can run without the .NET Framework if it does not launch any managed codes; the .NET Framework is required only when trying to launch a managed application.
The commonly used method to host CLR in an unmanaged program is to call
CorBindToRuntimeEx. However, in doing so, you will quickly find out the problem that your application cannot work without mscoree.dll, an unexpected dependency on the .NET Framework.
The cause of the issue is that
CorBindToRuntimeEx is exported from mscoree.dll. It will link to mscoree.dll at runtime. To resolve the dependency issue, we must avoid any functions provided by mscoree.dll.
The purpose of calling
is to create an instance of the
ICorRuntimeHost interface pointer. So we use
CoCreateInstance to create an
ICorRuntimeHost instance instead of using
The following code explains the details:
CoUninitialize() must be called before and after the call to
- 24th January, 2006: Initial post