在尝试托管 CLR 时,我不断收到以下消息:
error C2440: 'function' : cannot convert from 'const IID' to 'DWORD'
我的代码:
ICLRRuntimeHost *host = NULL;
HRESULT result = CorBindToRuntime(NULL, L"wks", CLSID_CLRRuntimeHost,
IID_ICLRRuntimeHost, (PVOID*)&host);
顺便说一句,这是用 C 语言编写的。不是 C++。
编辑:当我用 C++ 编译它时,它工作得很好。它在两种语言中的行为不应该相同吗?
最佳答案
来自 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
换句话来说,在C++中,这两个是引用,而在C中,它们是指针。您需要使用:
ICLRRuntimeHost *host = NULL;
HRESULT result = CorBindToRuntime(NULL, L"wks", &CLSID_CLRRuntimeHost,
&IID_ICLRRuntimeHost, (PVOID*)&host);
关于c - 错误 C2440 : 'function' : cannot convert from 'const IID' to 'DWORD' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27643762/