Paste Search Dynamic
ICLRMetaHost pMetaHost
  1.   ICLRMetaHost* pMetaHost = null;
  2.     ICLRRuntimeInfo* pRuntimeInfo = null;
  3.     bool bLoadable;
  4.     HRESULT hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
  5.     hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&pRuntimeInfo);
  6.     hr = pRuntimeInfo->IsLoadable(&bLoadable);
  7.     ICorRuntimeHost* pCorRuntimeHost = null;
  8.     hr = pRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (LPVOID*)&pCorRuntimeHost);
  9.     hr = pCorRuntimeHost->Start();
  10.    
  11.     IUnknown* pUnk = null;
  12.     _AppDomain* pAppDomain = null;
  13.     hr = pCorRuntimeHost->GetDefaultDomain(&pUnk);
  14.     hr = pUnk->QueryInterface(IID_PPV_ARGS(&pAppDomain));
  15.    
  16.     HANDLE hFile = CreateFile(L"E:\\Sources\\CSharp_Test4\\bin\\Debug\\CSharp_Test4.exe", GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, 0, null);            
  17.     if (hFile != INVALID_HANDLE_VALUE)
  18.     {
  19.         DWORD nNumberOfBytesRead = 0;
  20.         DWORD nFileSize = 0;
  21.         PVOID pFileBuffer = null;
  22.         nFileSize = GetFileSize(hFile, null);
  23.         pFileBuffer = VirtualAlloc(null, nFileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  24.         if (ReadFile(hFile, pFileBuffer, nFileSize, &nNumberOfBytesRead, null))
  25.         {
  26.             SAFEARRAYBOUND bounds[1];
  27.             bounds[0].cElements = (ULONG)nFileSize;
  28.             bounds[0].lLbound = 0;
  29.    
  30.             SAFEARRAY* psaBytes;
  31.             psaBytes = SafeArrayCreate(VT_UI1, 1, bounds);
  32.             SafeArrayLock(psaBytes);
  33.             memcpy(psaBytes->pvData, pFileBuffer, nFileSize);
  34.             SafeArrayUnlock(psaBytes);
  35.    
  36.             _Assembly* pAssembly;
  37.             hr = pAppDomain->Load_3(psaBytes, &pAssembly);
  38.             SafeArrayDestroy(psaBytes);
  39.    
  40.             _MethodInfo* pEntryPoint;
  41.             hr = pAssembly->get_EntryPoint(&pEntryPoint);
  42.             VARIANT v1, v2;
  43.             v1.vt = VT_NULL;
  44.             v1.plVal = null;                      
  45.             hr = pEntryPoint->Invoke_3(v1, null, &v2);
  46.    
  47.             pEntryPoint->Release();
  48.             pAssembly->Release();                      
  49.         }
  50.         VirtualFree(pFileBuffer, 0, MEM_RELEASE);
  51.         CloseHandle(hFile);
  52.     }
  53.  
Parsed in 0.016 seconds