不知道為什麼,之前還能在 Visual Studio 2005 下編譯得好好的工程,今天突然就碰到下面的問題:
Error 1 error MIDL2025 : syntax error : expecting ] or , near "annotation" C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\unknwn.idl 108 Error 2 error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\unknwn.idl 108
這個是 MIDL 編譯器相關的問題,當你給新版本的 Windows SDK 標頭檔使用舊版本的 MIDL 編譯器時,就會有這個問題。
解決的辦法,就是把你新版本的 MIDL 編譯器添加到 Visual Studio 的包含目錄裡。微軟 Mike Wasson 的部落格 MIDL error: 'annotation' 對此有著詳細的解釋,內容摘要如下:
A colleage recently got this error while compiling unknown.idl: 1>C:\Program Files\Microsoft SDKs\Windows\v6.0\Include\unknwn.idl(108) : error MIDL2025 : syntax error : expecting ] or , near "annotation"1>C:\Program Files\Microsoft SDKs\Windows\v6.0\Include\unknwn.idl(108) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation If you get this error, you are using a new version of the Windows headers with an older version of the MIDL compiler. Fix: 1. Make sure you installed the MIDL compiler when you installed the latest Windows SDK. It should appear under "Program Files\Microsoft SDKs\Windows\v6.0\Bin". Note: To install the MIDL compiler, you need to select Developer Tools / Windows Development Tools / Win32 Development Tools in the Windows SDK setup wizard. (At least, as of RC1.) 2. In Visual Studio, under Tools > Options > Projects and Solutions > VC++ Directories > Executable Files, add x:\Program Files\Microsoft SDKs\Windows\v6.0\bin to the top of the list.