#include <hidsdi.h>並在 Additional Include Directories 加入 DDK 標頭檔路徑(如 c:\winddk\inc\api)後, 編譯時會遇到一卡車的錯誤:
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2065: '_In_opt_z_' : undeclared identifier 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing ')' before 'const' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): warning C4229: anachronism used : modifiers on data are ignored 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2182: '_invoke_watson' : illegal use of type 'void' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2495: '_invoke_watson' : '__declspec(noreturn)' can only be applied to function declarations or definitions 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2059: syntax error : ')' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(56): error C2065: '_In_' : undeclared identifier 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(56): error C2144: syntax error : '_EXCEPTION_RECORD' should be preceded by ')' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(56): error C2448: '_except_handler' : function-style initializer appears to be a function definition 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(57): error C2144: syntax error : 'void' should be preceded by ';' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(58): error C2144: syntax error : '_CONTEXT' should be preceded by ';' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(59): error C2144: syntax error : 'void' should be preceded by ';' 1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(60): error C2059: syntax error : ')' ...原因是 DDK 標頭檔路徑中包括了很多標頭檔, 有些與 VC 內建的標頭檔有一樣的檔名, 而 VC 又會先從 Additional Include Directories 指定的路徑開始尋找標頭檔, 因此引入了不正確的資訊.
解決方法之一:
將 HID 標頭檔相關的檔案(hidsdi.h, hidpi.h, 及 hidusage.h)從 DDK 中複製出來, 這樣就可以不用在 Additional Include Directories 加入 DDK 標頭檔路徑了.
解決方法之二:
將 VC 內建的標頭檔路徑也放進 Additional Include Directories, 並且放於 DDK 標頭檔路徑之前:
Additional Include Directories = $(IncludePath);c:\winddk\inc\api;
沒有留言:
張貼留言