1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
// clrhosting.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <mscoree.h>
typedef HRESULT (FAR WINAPI *binder)(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor, REFCLSID rclsid, REFIID riid, LPVOID FAR *ppv);
int _tmain(int argc, _TCHAR* argv[])
{
ICLRRuntimeHost *host = NULL;
HMODULE mscoree = NULL;
binder Api_CorBindToRuntime = NULL;
mscoree = LoadLibrary(L"mscoree.dll");
if(mscoree != NULL)
{
Api_CorBindToRuntime = (binder)GetProcAddress(mscoree, "CorBindToRuntime");
if(Api_CorBindToRuntime != NULL)
{
if(Api_CorBindToRuntime(L"v2.0.50727", L"wks", CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*)&host) == S_OK)
{
HRESULT hr = S_OK;
DWORD returnValue = 0;
host->Start();
if(((hr = host->ExecuteInDefaultAppDomain(
L"d:\\poc\\clrhosting\\managed\\bin\\debug\\managed.dll",
L"MyNamespace.MyClass",
L"Probe",
L"1234567890",
&returnValue)) == S_OK) &&
(returnValue == 1234567890))
printf("Probing OK : .NET framework installed & working properly");
else
printf("ExecuteInDefaultAppDomain error : hr == %d ; returnValue == %d", hr, returnValue);
host->Release();
}
else
printf("CorBindToRuntime error : version of .NET framework not found");
}
else
printf("GetProcAddress(\"CorBindToRuntime\") error");
}
else
printf("LoadLibrary(\"mscoree.dll\") error : none of .NET framework versions is installed");
return 0;
} |
Partager