none
CorBindToCurrentRuntime failed when C++ Project compiled using VS2005 RRS feed

  • Question

  • Hi,

    I use unmanaged CLR Hosting APIs for loading CLR in windows native apps like notepad, calc etc. In case CLR is already hosted in the application ( like any .NET app ) I used CorBindToCurrentRuntime function published by mscoree.dll to get the handle to ICorRuntimeHost object and do some stuff by enumerating AppDomains. Things were working fine until I migrated my project from VS2003 to VS2005 IDE. I had to do this I faced some issues with my existing code when tried to get handle to Runtimehost using existing hosting APIs in CLR 4 process. I decided to check if new API i.e. "CLRCreateInstance" is exposed by mscoree.dll then use it to get handle to ICorRuntimeHost else use old function. In order to use this I included metahost.h file in my project and build my application.

    Now, for some reason I'm not able to get handle to ICorRuntimeHost interface inside .NET 1.1 application. If I use polcy file to run .NET 1.1 app as part of .NET 2.0 CLR, then call to "CorBindToCurrentRuntime"succeed and return the correct handle. Can anyone suggest what could possibly go wrong if I migrate from VS2003 to VS2005 IDE.

    I thought if it could be because of some .net framework dependeny  introduced when I built my c++/native project using VS2005, but I could not find one. My C++ project is a native project and doesn't depend on clr.

    Code Used to get handle to ICorRuntimeHost

        if( mCLRCreateInstanceFn != 0)//CLR4 function
        {
            ICLRMetaHost *pMetaHost = NULL;
            hr = (*mCLRCreateInstanceFn)(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
            if(hr != S_OK)
            {
                mDebug.Trace(TEXT("failed to get handle to CLRMetaHost...%x"),hr);
                return hostBindingPassed;
            }

    .....

    }

    else if(mCurrentRuntimeBindFunction != 0)

    {

                //Bind to the current CLR running within the application
                HRESULT hr = ( *mCurrentRuntimeBindFunction )(    NULL,
                    CLSID_CorRuntimeHost,
                    IID_ICorRuntimeHost,
                    (void**)&mpHost );
                if (hr != S_OK)
                {
                    mDebug.Trace(TEXT("failed to get handle to ICorRuntimeHost...%x"), hr);
                    return hostBindingPassed;
                }
    }

    Tuesday, August 24, 2010 1:46 PM

All replies

  • I tried to include the metahost.h file in my VS2003 project. Then it started complaining about __out_ecount_full. When I checked in VS2005 project I found that this macro is defined in sal.h, so I copied sal.h from Visual Studio 8/vc/include dir to my project include dir. But still I get the following error when I compile my code from VS2003 IDE.

    Compiling...
    source1.cpp
    ..\..\include\metahost.h(211) : error C2061: syntax error : identifier '__out_ecount_full'
    ..\..\include\metahost.h(212) : error C2059: syntax error : ')'
    ..\..\include\metahost.h(212) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    source2.cpp
    ..\..\include\metahost.h(211) : error C2061: syntax error : identifier '__out_ecount_full'
    ..\..\include\metahost.h(212) : error C2059: syntax error : ')'
    ..\..\include\metahost.h(212) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    source3.cpp
    ..\..\include\metahost.h(211) : error C2061: syntax error : identifier '__out_ecount_full'
    ..\..\include\metahost.h(212) : error C2059: syntax error : ')'
    ..\..\include\metahost.h(212) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    Generating Code...

     

    source1,source2 and source3.cpp are the files where I included metahost.cpp. The same project when I migrated to VS2005 works fine but at runtime it doesn't give me handle to ICorRuntimeHost using CorBindToCurrentRuntimefunction exposed by mscoree.dll, if application is .NET 1.1.

     

    Let me know if you need more information.

    Wednesday, August 25, 2010 5:13 AM