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"
#include


int _tmain(int argc, _TCHAR* argv[])
{
CComPtr 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;
}

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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