はじめてのCLRホスティング

CLRホスティングAPIを使ったことが無かったので実験。

#include <assert.h>
#include <stdio.h>
#include <mscoree.h>
#import <mscorlib.tlb> 

using namespace mscorlib;

int main (int argc, char* argv[]) 
{
    ICorRuntimeHost* pCLR = NULL;
    HRESULT hr = CorBindToRuntimeEx (
            L"v2.0.50727",
            L"wks",
            STARTUP_CONCURRENT_GC,
            CLSID_CorRuntimeHost,
            IID_ICorRuntimeHost,
            (PVOID*)&pCLR);
    if (FAILED (hr)) {
        printf ("CorBindToRuntimeEx failed.\n");
        return 0;
    }

    pCLR->Start ();

    IUnknown* pUnk = NULL;
    hr = pCLR->GetDefaultDomain (&pUnk);
    assert (pUnk);

    _AppDomain* pDomain = NULL;
    hr = pUnk->QueryInterface (__uuidof(_AppDomain), (PVOID*)&pDomain);
    assert (pDomain);

    hr = pDomain->ExecuteAssembly_2 (L"hello.exe");
    if (FAILED (hr)) {
        printf ("ExecuteAssembly failed.\n");
    }

    pUnk->Release ();
    pDomain->Release ();

    return 0;
}

/* Win32コンソールアプリ中でマネージドコードを実行
Hello
 */

まだ勉強中なので、これでどんな風に遊べるのか分かってません。(^^;