您的位置:首页 > 其它

VS2010编译的时候碰到winnt.h问题

2013-03-24 17:53 489 查看
/article/4323301.html

今天心血来潮,到微“软”那下了个VS2010玩玩。装好了就随便做个工程,结果编译的时候出来几个错误,全是在winnt.h里边。

------ Rebuild All started: Project: 123, Configuration: Debug Win32 ------
stdafx.cpp
c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

然后又是搜索大法,以这些信息搜索,找谁碰到这个问题。结果在微软的网站上看到了一条信息。

I built a new project to start the porting of an application written with CV6++, but the project stopped with the following errore just after few modifications to stdafx.h and the main include icarus2010.h.

1>------ Build started: Project: Icarus2010, Configuration: Debug Win32 ------
1>Build started 04/11/2009 16.51.46.
1>_PrepareForBuild:
1> Touching "Debug\Icarus2010.unsuccessfulbuild".
1>ClCompile:
1> stdafx.cpp
1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programmi\microsoft sdks\windows\v7.0a\include\exdisp.h(842): error C2061: syntax error : identifier 'SHANDLE_PTR'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.93
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The modifications in the stdafx were

#pragma warning(disable: 4786)
#pragma warning (disable:4996)
#pragma warning (disable:4244)
#pragma warning (disable:4189)
#pragma warning (disable:4100)

and the modifications in the main inlcude were some include files from the VC6++ application. For a while the new project worked!
详细信息 (展开) Product Language
EnglishVersion
Visual Studio 2010 Beta 2Operating System
Windows XP
Operating System Language

ItalianSteps to Reproduce
unknownActual Results
unknownExpected Results
soon      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

///////////////////////////////////////////////////////////////////////

由 Microsoft 在 2009/11/5 1:29 发送
Thank you for your feedback, We are currently reviewing the issue you have submitted.
由 Microsoft 在 2009/11/8 20:41 发送
Thanks for reporting this issue.

In order to fix the issue, we must first reproduce the issue in our labs. We are unable to reproduce the issue with the steps you provided.

Please provide us with a demo zipped project file so that we can conduct further research.

It would be greatly appreciated if you could provide us with that information as quickly as possible. If we do not hear back from you within 7 days, we will close this issue.

Thanks again for your efforts and we look forward to hearing from you.

Visual Studio Product Team

由 Microsoft 在 2009/11/9 11:54 发送
Hi -

Do you have the DirectX SDK installed on the machine? We have seen some cases where the DirectX SDK installer modifies the Visual Studio include path and puts the DirectX SDK entries first. This causes the build to use DirectX versions of some files that are a different version that the files in the Visual Studio SDK.

Try changing the order of include directories in VS so the DirectX SDK entries are last. That may solve the problem.

Mike Robinson
Program Manager
Windows SDK Team

有个家伙也碰到了这个问题。微软的回答是,你可能装了DIRECTX SDK,你到包含目录设置把DX SDK的目录往后移就可以了。

第一次用不熟这东西,只好以“winint.h”为关键字找,结果从网上找到一个在VS2005设置DX SDK的。

解决方法:在winnt.h中加上以下语句

#define POINTER_64 __ptr64

typedef void *PVOID;
typedef void * POINTER_64 PVOID64;

个人认为最好不去改winnt.h.
有时需要要调整include文件夹的顺序来解决问题,platform SDK中的winnt.h
DDK中的,vc6.0 自带的winnt.h有多个。 dxsdk 中的这些所用到的winnt.h版本不同。

通过调整IDE 工具-> 选项-> 项目vc++目录;包含文件include 的顺序来解决这类问题
使dxsdk需要的winnt.h所在文件夹在最上面。


DirectShow 在VS2005中环境配置
先介绍系统环境:
XP Professional sp2
visual studio 2005 version 8.0.50727.42
DirectX 9.0(9.0b) SDK Update - (Summer 2003)

首先,就是编译baseclasses,什么是baseclasses?打开你的dx的sdk安装目录,例如:
D:\DX90SDK\Samples\C++\DirectShow\
这里就有一个叫baseclasses的工程,为安全起见,请先备份此工程。

1,双击baseclasses.sln打开,提示我们需要转换工程,按提示转换就是了,编译
提示错误:
1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer'
1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\DX90SDK\Samples\C++\DirectShow\BaseClasses\ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int第一类问题的解决:错误发生在:operator=(LONG);函数定义中,这是因为在VC6中,如果没有显示的指定返回值类型,编译器将其视为默认整 形;但是vs2005不支持默认整形,解决这个问题不能修改每个没有显示指示返回值类型的函数地方,可以用wd4430来解决;具体的在工程选项中的c+ +/Command Line中添加/wd4430即可。

2,在Tools->Options->Projects and solutions->vc++ directories->show directories for里选择include files
然后增加
D:\DX90SDK\Include
D:\DX90SDK\Samples\C++\DirectShow\BaseClasses
D:\DX90SDK\Samples\C++\Common
可能会问题依旧,调整一下include files的顺序吧,把他们都放在最后,例如我的环境:
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(VCInstallDir)PlatformSDK\include
$(FrameworkSDKDir)include
D:\DX90SDK\Include
D:\DX90SDK\Samples\C++\DirectShow\BaseClasses
D:\DX90SDK\Samples\C++\Common
然 后在project->BaseClasses properties->configuration->C/C++ -> General->Additional Include Directories里面的内容(.,..\..\..\..\include)删掉,重新编译,PVOID64的错误消失,原因如下:
POINTER_64 是一个宏,在64位编译下起作用,它包含在SDK目录下的BASETSD.H中(Microsoft Visual Studio 8\VC\PlatformSDK\Include\basetsd.h(23):#define POINTER_64 __ptr64),但DXSDK自己也带了一个basetsd.h,里面没有定义POINTER_64,从而导致出错,只需要改变include files的优先级即可。当然,也可以改写winnt.h中的代码,在下面这两行:typedef   void   *PVOID;
typedef   void   *POINTER_64   PVOID64;
之前增加一行:
#define   POINTER_64   __ptr64

3,到目前为止,还剩下:
BaseClasses\ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
这个错误,解决方法如下:
打开project->BaseClasses properties->configuration->C/C++ ->Command Line,增加/wd4430选项。
4, 接着编译,提示error C2065: 'Count' : undeclared identifier等等错误,这个是微软的历史遗留问题了,C++标准语法的问题,因为在之前在for循环内定义的变量可以在for之外的地方使用,即 在第一个for里for(int i,...),以后的for再使用i不必再声明,解决方法也很简单,打开project->BaseClasses properties->configuration->C/C++->Language->Force Comformance in For Loop Scrope设置为No即可。当然,也可以手动改代码,增加一个声明就是了。

经过上面几个步骤,应该是可以顺利编译了,对于其它版本的工程,照样设置就可以了,总共编译出下面4个文件备用:
BaseClasses\Debug\strmbasd.lib
BaseClasses\Debug_Unicode\strmbasd.lib
BaseClasses\Release\STRMBASE.lib
BaseClasses\Release_UnicodeSTRMBASE.lib

在lib里面加入

commctrl.lib
coredll.lib
strmiids.lib
strmbase.lib
uuid.lib
ole32.lib
commdlg.lib

你或许需要在Tools->Options->Projects and solutions->vc++ directories->show directories for->library files里把它们加进去。
赶快编译DX90SDK\Samples\C++\DirectShow\Players\PlayDMO工程试试看吧。

以上资料整理自下面3个blog,一并列出:
DirectShow在VS2005中PVOID64问题和配置问题 http://www.cnblogs.com/RunOnTheWay/archive/2008/01/17/1043705.html DirectShow 在VS2005中环境配置 http://blog.cnii.com.cn/?uid-75821-action-viewspace-itemid-24418 Some DirectShow Samples Break in Visual Studio 2005 http://blogs.msdn.com/mikewasson/archive/2005/05/23/some-directshow-samples-break-in-visual-studio-2005.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: