本文介绍了错误C2440:'功能':无法从'常量IID'到'DWORD'转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试举办CLR,我不断收到这样的:

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

错误C2440:'功能':无法从'常量IID转换为DWORD

我的code:

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

这是在C,顺便说一句。不是C ++。

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

编辑:当我编译这与C ++,它工作得很好。难道不应该具有相同的行为在任何语言?

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

推荐答案

从guiddef.h:

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

在换言之,在C ++中,这两个是引用,并且在C,它们是指针。您需要使用:

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);

这篇关于错误C2440:'功能':无法从'常量IID'到'DWORD'转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:10