不知道为什么,之前还能在 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.