Cromon

NETLoader.cpp

Oct 9th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. HRESULT NETLoader::LoadModule(const wchar_t* moduleName)
  2. {
  3.     ICLRMetaHost* pMetaHost = nullptr;
  4.     auto hResult = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));
  5.     if(FAILED(hResult))
  6.         return hResult;
  7.  
  8.     wchar_t clrVersion[MAX_PATH];
  9.     DWORD dwLen = MAX_PATH;
  10.     hResult = pMetaHost->GetVersionFromFile(moduleName, clrVersion, &dwLen);
  11.     if(FAILED(hResult)) {
  12.         pMetaHost->Release();
  13.         return hResult;
  14.     }
  15.  
  16.     ICLRRuntimeInfo* pRuntimeInfo = nullptr;
  17.  
  18.     hResult = pMetaHost->GetRuntime(clrVersion, IID_PPV_ARGS(&pRuntimeInfo));
  19.     if(FAILED(hResult))
  20.     {
  21.         pMetaHost->Release();
  22.         return hResult;
  23.     }
  24.  
  25.     pMetaHost->Release();
  26.  
  27.     ICLRRuntimeHost* pRuntimeHost = nullptr;
  28.     hResult = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_PPV_ARGS(&pRuntimeHost));
  29.     if(FAILED(hResult))
  30.     {
  31.         pRuntimeInfo->Release();
  32.         return hResult;
  33.     }
  34.  
  35.     pRuntimeInfo->Release();
  36.  
  37.     hResult = pRuntimeHost->Start();
  38.     if(FAILED(hResult))
  39.     {
  40.         pRuntimeHost->Release();
  41.         return hResult;
  42.     }
  43.  
  44.     DWORD dwResult = 0;
  45.     hResult = pRuntimeHost->ExecuteInDefaultAppDomain(moduleName, L"TrackObject.Entry", L"Main", L"NETLoader_Call", &dwResult);
  46.     if(FAILED(hResult))
  47.     {
  48.         pRuntimeHost->Release();
  49.         return hResult;
  50.     }
  51.  
  52.     pRuntimeHost->Release();
  53.  
  54.     return S_OK;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment