oaidl.h(319):error C2057:expected constant expression [英] oaidl.h(319): error C2057: expected constant expression

查看:541
本文介绍了oaidl.h(319):error C2057:expected constant expression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从Visual Studio 2010切换到Visual Studio 2012.我正在开发的项目使用 BitwiseEnums 库,来自 MiLi 。根据说明这里,我只包含BitwiseEnums库,因此只有要添加到我的项目的文件是 bitwise_enums.h

I've recently switched from Visual Studio 2010 to Visual Studio 2012. The project I'm working on uses the BitwiseEnums library from MiLi. I'm including just the BitwiseEnums library as per the instructions here, so the only file being added to my project is bitwise_enums.h.

在VS2010我没有问题。在VS2012我得到以下错误消息每当我#include bitwise_enums.h并尝试编译:

In VS2010 I had no issues. In VS2012 I'm getting the following error message whenever I #include bitwise_enums.h and try to compile:

1>c:\program files (x86)\windows kits\8.0\include\um\oaidl.h(319): 
error C2057: expected constant expression

当我检查我的项目的外部依赖项,它会列出文件oaidl.h。查看这个文件,我发现以下语句结束于第319行。

When I check the external dependencies for my project, it does list the file oaidl.h. Looking inside this file, I find the following statement which ends on line 319.

typedef /* [v1_enum] */ 
enum tagSF_TYPE
    {
        SF_ERROR    = VT_ERROR,
        SF_I1   = VT_I1,
        SF_I2   = VT_I2,
        SF_I4   = VT_I4,
        SF_I8   = VT_I8,
        SF_BSTR = VT_BSTR,
        SF_UNKNOWN  = VT_UNKNOWN,
        SF_DISPATCH = VT_DISPATCH,
        SF_VARIANT  = VT_VARIANT,
        SF_RECORD   = VT_RECORD,
        SF_HAVEIID  = ( VT_UNKNOWN | VT_RESERVED ) 
    }   SF_TYPE; // Line 319

我的问题是:


  1. 什么是oaidl.h,是什么导致它包含在我的项目中?

  2. 错误消息是什么意思, ?


推荐答案

我已经设法将此缩小到bitwise_enums.h和Windows.h之间的某种命名冲突,我也包括在项目中。我注意到,如果我包含整个MiLi库,我没有得到错误,因为mili.h使用 #define NAMESPACE_BEGIN #define NAMESPACE_END ,而以建议的方式此处,表示bitwise_enums.h的内容最终会污染全局命名空间。我仍然不完全清楚为什么这会导致一个问题,因为我似乎找不到冲突,也不清楚为什么它在VS2010工作。但是,我能够通过修改#define指令来解决它,以便他们在bitwise_enums.h中创建一个命名空间:

I've managed to narrow this down to naming conflict of some kind between bitwise_enums.h and Windows.h, which I was also including in the project. I noticed that I didn't get the error if I included the entire MiLi library, because mili.h places everything inside a namespace using #define NAMESPACE_BEGIN and #define NAMESPACE_END, whereas defining them in the way suggested here, means that the contents of bitwise_enums.h end up polluting the global namespace. I am still not altogether clear on why this causes a problem, as I can't seem to locate the clash, nor am I clear on why it worked in VS2010. However, I was able to solve it by altering the #define instructions so that they create a namespace inside bitwise_enums.h:

#define NAMESPACE_BEGIN namespace Mili
#define NAMESPACE_END }
#include <bitwise_enums.h>
#undef NAMESPACE_BEGIN
#undef NAMESPACE_END

另一个解决方案是包含mili。 h并按照此链接的第二个建议,但由于我只需要一个库,我不喜欢有很多行,单独排除我不想要的库。

Another solution is to include mili.h and follow the second suggestion at this link, but since I only need one library, I prefer not to have to have lots of lines individually excluding the libraries I don't want.

希望这个答案将是有用的,如果任何人在未来最终在使用这种特定方法来包含来自MiLi的单个库,同时还包括VS2012中的Windows.h(可能不太可能是组合)!

Hopefully this answer will be useful if anyone in future ends up in the same obscure situation as myself, using that specific method of including a single library from MiLi, whilst also including Windows.h in VS2012 (probably an unlikely combination)!

这篇关于oaidl.h(319):error C2057:expected constant expression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆