tags:

views:

453

answers:

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?

A: 

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
Now the error is: "error C2440: 'function' : cannot convert from 'const IID' to 'const IID *const '"
David Brown
Strangely, when I compile the above in C++, everything works fine. How could this be?
David Brown
A: 

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