当我在我的VS2010项目中包含一个标准库时,我得到了一些像这样的错误(这些错误来自 shellapi.h )。添加类似 Windows.h 或 Wininet.h 之类的内容时,我会遇到类似的错误。
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'DragQueryFileA'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ')' before identifier 'hDrop'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2059: syntax error : ')'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C2086: 'int EXTERN_C' : redefinition
我确信这只是与项目设置有关,但我不知道我需要改变什么样的设置。我应该从哪里开始?
更新
解决方案是确保首先加载了windows.h。我不知道它是依赖于那个。为了将来参考,我应该在哪里看到这种依赖?
答案 0 :(得分:5)
添加
时出现了完全相同的错误#include <shellapi.h>
到我的一个文件中。我通过添加
解决了这个问题#include <windows.h>
直接在它之前。
(你必须爱 - 或者更确切地说,讨厌 - 没有#include
他们自己需要的标题的Windows标题。如果我在自己的代码中这样做我我的上级会大吼大叫!)
答案 1 :(得分:2)
当您的某个包含损坏,然后包含标准标头时会发生这种情况,因为您的语法错误会直接继续。例如,如果您忘记了半数,那么请包含另一个标头,该标头将报告语法错误。出于这个原因,您应该始终首先包括“干净”标题,如系统标题,然后是自定义标题。