2

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?

David Brown
  • 35,411
  • 11
  • 83
  • 132

2 Answers2

1

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);
MSN
  • 53,214
  • 7
  • 75
  • 105
0

The last parameter of CorBindToRuntime is defined as LPVOID*, not PVOID*. Maybe thats the problem?

HRESULT CorBindToRuntime (
        [in]  LPCWSTR     pwszVersion, 
        [in]  LPCWSTR     pwszBuildFlavor, 
        [in]  REFCLSID    rclsid, 
        [in]  REFIID      riid, 
        [out] LPVOID FAR  *ppv
);
RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92