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

Popular posts from this blog

Quricol - QR code generator library

Smir - backup and restore Windows desktop icons position

EIDNative Library 2.0 released