Accessing managed code from native application

// 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"

int _tmain(int argc, _TCHAR* argv[])
CComPtr pHost;
DWORD dRetVal;
CorBindToRuntimeEx(NULL, NULL, 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void**)&pHost);
// 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);
return 0;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s