none
Loading CLR in native (unmanaged) C++ COM in proc dll RRS feed

  • Question

  • Hi,

    I am trying to load the CLR in a native C++ in-proc COM dll.

    1. First of all is this legit/ok to do?

    2. I want to use .NET version 2 or later, for which MSDN (http://msdn.microsoft.com/en-us/library/01918c6x(v=vs.90).aspx) mentions using ICLRRuntimeHost and not ICorRuntimeHost. Here is some code which runs into a problem when Querying (E_NOINTERFACE) for the ICorRuntimeHost interface. I tried this in my in-proc COM dll as well as a native C++ standalone console app. What could the problem be?

    	HRESULT hr = S_OK;
    
    	TCHAR buf[256];
    
    
    
    	// Bind to the runtime.
    
     CComPtr<ICLRRuntimeHost> pClrHost;
    
    
    
     hr = CorBindToRuntimeEx(
    
      NULL, // Load the latest CLR version available
    
      L"svr", // Workstation GC ("wks" or "svr" overrides)
    
      0,  // No flags needed
    
      CLSID_CLRRuntimeHost,
    
      IID_ICLRRuntimeHost,
    
      (PVOID*)&pClrHost);
    
    
    
    	if (SUCCEEDED(hr) && pClrHost) {
    
    		OutputDebugString(L"CVSAPIObject::Initialize CorBindToRuntimeEx succeeded");
    
    
    
    	 
    
    		// Now, start the CLR. (probably does not necessarily need to be done before calling QueryInterface below - was just playing
    
    		hr = pClrHost->Start();
    
    		if (SUCCEEDED(hr)) {
    
    			OutputDebugString(L"CVSAPIObject::Initialize CLR Start succeeded");
    
    		} else {
    
    			_stprintf(buf, L"CVSAPIObject::Initialize CLR Start failed: hr=0x%x", hr);
    
    			OutputDebugString(buf);
    
    		}
    
    
    
    
    
    		CComPtr<ICorRuntimeHost> pCorRTHost;
    
    		hr = pClrHost->QueryInterface(IID_ICorRuntimeHost, (void **)&pCorRTHost); // fails with E_NOINTERFACE
    
    		if (SUCCEEDED(hr)) {
    
    

    3. My ultimate aim is to create a named app domain. So if I directly start using ICorRuntimeHost from the CorBindToRuntimeEx step itself I am able to call CreateDomain on it successfully in my native C++ console app. But its recommended that I do not do this since I want to use .NET 2.0 onwards right? I need to use ICLRRuntimeHost ? How do I get ICorRuntimeHost?

     Thanks in advance!

    AbDiv


    • Edited by AbDiv Monday, June 20, 2011 6:07 AM Forgot a point
    Monday, June 20, 2011 5:57 AM

Answers