// CLRHost.cpp : Hosting managed code in native Windows application
// This demo shows how to access the managed code from the native application
// and call the C# class method
#include "stdafx.h"
#include <mscoree.h>
int _tmain(int argc, _TCHAR* argv[])
{
CComPtr<iclrruntimehost> pHost;
DWORD dRetVal;
CorBindToRuntimeEx(NULL, NULL, 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void**)&pHost);
pHost->Start();
// Once you've loaded and started the CLR, the easiest way to load and run
// your managed code is to use the ExecuteInDefaultApp-Domain
//method on ICLRRuntimeHost. This will simply load a managed assembly
// and execute a method on it:
pHost->ExecuteInDefaultAppDomain(L"TestAssembly.dll", L"Test.MyClass", L"Execute", L"Hello", &dRetVal);
pHost->Stop();
return 0;
}
Comments
Post a Comment