Search code examples
cclr-hosting

error C2440: 'function' : cannot convert from 'const IID' to 'DWORD'


While trying to host the CLR, I keep getting this:

error C2440: 'function' : cannot convert from 'const IID' to 'DWORD'

My code:

ICLRRuntimeHost *host = NULL;
HRESULT result = CorBindToRuntime(NULL, L"wks", CLSID_CLRRuntimeHost, 
    IID_ICLRRuntimeHost, (PVOID*)&host);

This is in C, by the way. Not C++.

EDIT: When I compile this with C++, it works just fine. Shouldn't it behave the same in either language?


Solution

  • From guiddef.h:

    #ifndef _REFIID_DEFINED
    #define _REFIID_DEFINED
    #ifdef __cplusplus
    #define REFIID const IID &
    #else
    #define REFIID const IID * __MIDL_CONST
    #endif
    #endif
    
    #ifndef _REFCLSID_DEFINED
    #define _REFCLSID_DEFINED
    #ifdef __cplusplus
    #define REFCLSID const IID &
    #else
    #define REFCLSID const IID * __MIDL_CONST
    #endif
    #endif
    

    In other words, in C++, those two are references, and in C, they are pointers. You need to use:

    ICLRRuntimeHost *host = NULL;
    HRESULT result = CorBindToRuntime(NULL, L"wks", &CLSID_CLRRuntimeHost,
        &IID_ICLRRuntimeHost, (PVOID*)&host);