2010-06-01 169 views
4

當我在VS2010項目中包含一個標準庫時,會出現類似這樣的錯誤(這些錯誤來自shellapi.h)。在類似WINDOWS.HWininet.h或類似的東西加入,當我得到類似的錯誤。VS2010包含標準庫時出現大量錯誤

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 

我確定這只是一個項目設置,但我不知道我需要改變什麼設置。我應該從哪裏開始?

UPDATE

的解決方案是確保WINDOWS.H首次加載。我不知道它依賴於此。爲了將來的參考,我應該在哪裏查看依賴關係?

+2

請告訴我們您的所有包括。 – SLaks 2010-06-01 22:05:09

+3

你無法不先#包括WINDOWS.H#包括shellapi.h。讓我們看看你的列表,當你開始WINDOWS.H – 2010-06-01 22:11:25

回答

2

發生這種情況時,你包括一個壞了,那麼你有一個標準的頭,因爲你的語法錯誤,直接進行。例如,如果您忘記了一個半,然後包含另一個標題,該標題將報告語法錯誤。出於這個原因,你應該總是包含「乾淨的」頭像系統頭,然後自己定義的頭。

+0

雖然這可能是真實的,它是不是一個好足夠的理由在你自己的,包括系統頭。我總是首先包含我自己的頭文件,然後包含其他庫的頭文件(供應商,提升等),最後是系統頭文件;這有助於確保您編寫的頭文件可以「獨立」,幷包含#include語句,用於編譯它們自己需要的所有內容。 – aldo 2014-02-07 17:55:46

5

我加入

#include <shellapi.h> 

到我的文件之一,當有這些完全相同的錯誤。我通過添加

#include <windows.h> 

直接在它之前解決了問題。

(你得愛 - 或者更確切地說, - Windows頭不#include他們自己需要的報頭。如果我這樣做,在我自己的代碼,我會得到在由我的上司大喊。 !)

+0

...或者說恨它... +1 – Iuliu 2014-10-24 10:59:47

+0

姿是,你怎麼說?abseurd! – Claudiu 2015-04-30 17:44:54

相關問題