error C2146: 语法错误 : 缺少“;”(在标识符“PVOID64”的前面)

在使用VS2008编译工程的时候,发现编译出错,提示以下内容:

1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236) : error C2146: 语法错误 : 缺少“;”(在标识符“PVOID64”的前面)
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C2146: 语法错误 : 缺少“;”(在标识符“Buffer”的前面)
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

在网上找了一些资料,说是因为有DirectX头文件引入顺序问题,要打开 工具->选项->项目和解决方案->VC++ 目录,确保条目 $(WindowsSdkDir)\include 和 $(FrameworkSDKDir)include 在任何DirectX目录的前面,但发现并没有DirectX目录,后来才找到原因,是由于在本地目录中加入DirectX的头文件,把本地目录中的BaseTsd.h删掉就行了。

打开winnt.h头文件,定位到产生error C2146的第236行:

typedef void * POINTER_64 PVOID64;

初步断定,原因应该是编译器不认识POINTER_64。网上查了一下,原来是由于我的项目依赖的DirectX 8.1 SDK,其Include directory包含的BaseTsd.h是一个早期的版本,其中还没有定义POINTER_64

原文:
This is indeed the problem. The DirectX Include directory contains an early version of BaseTsd.h which does not include the definition for POINTER_64. You should instead use the version of BaseTsd.h in the Platform SDK, either the one that ships with Visual Studio 2005 (C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\BaseTsd.h) or in an updated Microsoft SDK installation. In order to get the compiler to use the right file, just remove BaseTsd.h from the DirectX Include directory.

Comments are closed.