gpt4 book ai didi

c - 错误 C2440 : 'function' : cannot convert from 'const IID' to 'DWORD'

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:35 27 4
gpt4 key购买 nike

在尝试托管 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/1351589/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com