我们正在考虑将我们的应用程序从VS2008转移到VS2010。

我们使用“属性编程”生成一些COM对象,并自动生成IDL。

两个文件的导入指令是不同的,并且汇编在VS2010上失败。

在VS2008上,它生成类似的东西:

import "docobj.idl";
.

在VS 2010

import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wincrypt.idl";
import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\exdisp.idl";
import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\shldisp.idl";
import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\prsht.idl";
import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\mshtmhst.idl";
import "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\mshtml.idl";
import "c:\program files (x86)\microsoft sdks\windows\v7.0a\include\dimm.idl";
import "c:\program files (x86)\microsoft sdks\windows\v7.0a\include\dispex.idl";
.

在vs2010上编译idl时,它会生成以下错误

20>  Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555 
20>  Copyright (c) Microsoft Corporation. All rights reserved.
20>  Processing .\_my_idl.idl
20>  _my_idl.idl
20>  Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wincrypt.idl
20>  wincrypt.idl
20>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wincrypt.idl(47): error MIDL2025: syntax error : expecting a type specification or a storage specifer or a type qualifier near "WCHAR"
20>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wincrypt.idl(47): error MIDL2026: cannot recover from earlier syntax errors; aborting compilation
20>LINK : fatal error LNK1240: failed to compile IDL content
.

手动删除“wincrypt.idl”导入指令删除编译错误,但这不是一个解决方案,因为IDL是自动生成的。

我并不肯定为什么两个idl是不同的,什么是责任添加导入指令;甚至如何修复MIDL编译错误。

任何想法?

提前感谢。

max。

有帮助吗?

解决方案

它缺少

 #import "ocidl.idl"
.

您可以使用代码中的[IMPORTIDL]属性来解决它。

归属编程有点错误,它基本上被弃用,因为它被删除为VS2008中的ATL项目向导的选项。有关您的代码库的长期维护,请考虑删除它。您可以使用自动生成的.idl作为启动的方法。

其他提示

Perhaps I was using the [importidl] attribute wrong, but I couldn't get Hans' answer to fix this problem. But the fix here worked. Just add this to the top of your stdafx.h file:

[idl_quote("import \"ocidl.idl\";")];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top