// You need to link with the static lib mscoree.lib
// to compile this C++ file.
#include <mscoree.h>
// The import must be done on a single line.
#import <mscorlib.tlb> raw_interfaces_only ...
... high_property_prefixes("_get","_put","_putref") ...
... rename("ReportEvent","ReportEventManaged") rename_namespace("CRL")
// We use the namespace ComRuntimeLibrary.
using namespace CRL;
ICLRRuntimeHost * pClrHost = NULL;
void main (void){
// Get a COM pointer of type ICorRuntimeHost on the CLR.
HRESULT hr = CorBindToRuntimeEx(
NULL, // We ask for the most recent version of the CLR.
NULL, // We ask for the workstation version of the CLR.
0,
CLSID_CLRRuntimeHost,
IID_ICLRRuntimeHost,
(LPVOID *) &pClrHost);
if (FAILED(hr)){
printf("Can't get a pointer of type ICLRRuntimeHost!");
return;
}
printf("We got a pointer of type ICCLRRuntimeHost.\n");
printf("Launch the CLR.\n");
pClrHost->Start();
// Here, we can use our COM pointer pClrHost on the CLR.
pClrHost->Stop();
printf("CLR stopped.\n");
pClrHost->Release();
printf("Bye!\n");
}