none
ICorRuntimeHost vs. ICLRRuntimeHost

    Question

  • Hello,

    since  CorBindToRuntimeEx is deprecated in .Net 4.0 I changed my old C++ (shim) code

    ICorRuntimeHost  *m_pHost;
    
    HRESULT hr = S_OK;
    
    hr = CorBindToRuntimeEx(0, 0, 0, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (PVOID*) &m_pHost);
    
    

    according to

    http://msdn.microsoft.com/en-us/library/01918c6x%28VS.100%29.aspx

    to

    ICLRRuntimeHost  *m_pHost;
    
    LPCWSTR szclrversion = L"v4.0.30319";
    HRESULT hr = S_OK;
    
    ICLRMetaHost    *m_pMetaHost;
    
    hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*) &m_pMetaHost);
    
    if (hr != S_OK) {
    	return hr;
    }
    
    ICLRRuntimeInfo *m_pRuntimeInfo;
    
    hr = m_pMetaHost->GetRuntime (szclrversion, IID_ICLRRuntimeInfo, (LPVOID*) &m_pRuntimeInfo);
    if (hr != S_OK) {
    	return hr;
    }
    
    hr = m_pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*) &m_pHost );
    
    

    But now I get the compiler errors

    'CreateDomainSetup' : is not a member of 'ICLRRuntimeHost'
    CreateDomainEx' : is not a member of 'ICLRRuntimeHost'
    'UnloadDomain' : is not a member of 'ICLRRuntimeHost'

    What do I miss ?

    with best regards

       Hendrik Schmieder

     

     

     

    Wednesday, May 18, 2011 2:04 PM

All replies

  • ICLRRuntimeHost contains no CreateDomainSetup method, instead, you may want to get an ICorRuntimeHost first, and then invoke CreateDomainSetup on the ICorRuntimeHost interface:

     

    #include"stdafx.h"

    #include<mscoree.h>

    #include<metahost.h>

    #pragmacomment(lib, "mscoree.lib")

    int _tmain(int argc, _TCHAR* argv[])

    {

    HRESULT hr;

    ICLRMetaHost *pMetaHost = NULL;

    hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);

    ICLRRuntimeInfo * lpRuntimeInfo = NULL;

    hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&lpRuntimeInfo);

    ICLRRuntimeHost * lpRuntimeHost = NULL;

    hr = lpRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&lpRuntimeHost);

    hr = lpRuntimeHost->Start();

    ICorRuntimeHost* lpCorRuntimeHost = NULL;

    hr = lpRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (LPVOID *)&lpCorRuntimeHost);

    // To do.

    return 0;

    }


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 19, 2011 9:52 AM
  • I already thought of that,

     

    but since it is stated

    "In the .NET Framework version 2.0, this interface is superceded by ICLRRuntimeHost"

    in http://msdn.microsoft.com/en-us/library/ms164320.aspx

    (ICorRuntimeHost Interface)

    I thought that I jsut miss additional lookup calls to get additional objects for creating additional appdomain in which the c# addin is then loaded.

    If such a behaviour is not possible, then ICLRRuntimeHost doesn't really supercede ICorRuntimeHost.

    But if ICorRuntimeHost also works with .NET 4.0 (loading a .NET 4.0 C# assembly) then I would happily use

    GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost,...)

    with best regards

       Hendrik Schmieder

     

     


    Thursday, May 19, 2011 2:50 PM
  • As per MSDN documentation (http://msdn.microsoft.com/en-us/library/ms164320.aspx) ICorRuntimeHost interface is superseded by ICLRRuntimeHost.

     

    The MSDN for ICLRRuntimeHost states:

     

    Provides functionality similar to that of the ICorRuntimeHost interface provided in the .NET Framework version 1, with the following changes:

     

    • The addition of the SetHostControl method to set the host control interface.
    • The omission of some methods provided by ICorRuntimeHost.

     

     

    The link http://msdn.microsoft.com/en-us/library/ms164408.aspx provides list of function available for ICLRRuntimeHost. So, the 'CreateDomainSetup', ‘CreateDomainEx' and 'UnloadDomain' not there in ICLRRuntimeHost interface.

     

    Please let me know what you are trying achieve using framework 4.0?


    bill boyce
    Friday, June 03, 2011 7:59 PM
    Moderator
  • Sorry for the delay,

    since I was out of town.

    I looks like you haven't read my post from 19. May carefully enough.

    There I stated that the MSDN claims that ICorRuntimeHost interface is superseded by ICLRRuntimeHost.

    But since some important methods are missing this is not the case.

    At least it is not documented what to use instead.

     

     

    Monday, June 27, 2011 12:41 PM
  • Hi,

    Hendrik, I feel the same way as you did when you posted your last reply. I used Eric Yang's code sample and it worked fine, but encountered an access violation error . I do not think the use of ICorRuntimeHost is troublesome, but the dearth of sample code on the .NET 4.0 CLR hosting API is a pain point.

    Did you find a resolution to your issues?

    Cheers

    Sunday, May 06, 2012 12:53 AM
  • I changed my code I posted on Wednesday, May 18, 2011 2:04 PM on two places.

    ICLRRuntimeHost  *m_pHost;
    ->
    ICorRuntimeHost  *m_pHost;

    hr = m_pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*) &m_pHost );
    ->
    hr = m_pRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (LPVOID*) &m_pHost );

      Hendrik

    Monday, May 07, 2012 8:36 AM