wpsapi.tlh(11) : fatal error C1083: 无法打开包括文件:“”: No such file or directory

来源:互联网 发布:幼儿园床淘宝 编辑:程序博客网 时间:2024/06/15 04:48

环境:cpu64,win7 64操作系统,vs2008,office2013,wps2013个人版

1.由于换了一个笔记本,xp->win7,office2010->2013,wps2012->2013,导致原来的代码不能用了

源代码stdafx.h

#import "..\Lib\wps\2013.9.1.0.4715\wpsapi.dll" //rename("RGB", "WPSRGB")#import "..\lib\msword.olb"  auto_search auto_rename no_auto_exclude rename("ExitWindows", "WordExitWindows")
编译报错:

wpsapi.tlh(11) : fatal error C1083: 无法打开包括文件:“”: No such file or directory

2.新建一小工程,让编译器自动引用库(如msword.olb引用的MSO.DLL,VBE6EXT.OLB)

#import "D:\Program Files\Microsoft Office\Office15\MSWORD.OLB" auto_search auto_rename no_auto_exclude#import "D:\Program Files (x86)\Kingsoft\WPS Office\9.1.0.4715\office6\wpsapi.dll" auto_search auto_rename no_auto_exclude
编译报错:

1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1034) : error C2011: “Office::MsoLineDashStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1034) : 参见“Office::MsoLineDashStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1051) : error C2011: “Office::MsoLineStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1051) : 参见“Office::MsoLineStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1061) : error C2011: “Office::MsoArrowheadStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1061) : 参见“Office::MsoArrowheadStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1072) : error C2011: “Office::MsoArrowheadWidth”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1072) : 参见“Office::MsoArrowheadWidth”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1080) : error C2011: “Office::MsoArrowheadLength”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1080) : 参见“Office::MsoArrowheadLength”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1088) : error C2011: “Office::MsoFillType”: “enum”类型重定义

.....

3.貌似变量重复定义,于是手动引用库

#import "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\MSO.DLL" rename("RGB", "_RGB1")import "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"#import "D:\Program Files\Microsoft Office\Office15\MSWORD.OLB" rename("ExitWindows", "_ExitWindows"),rename("FindText", "_FindText")#import "D:\Program Files (x86)\Kingsoft\WPS Office\9.1.0.4715\office6\ksoapi.dll"
编译报错:

1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1034) : error C2011: “Office::MsoLineDashStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1034) : 参见“Office::MsoLineDashStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1051) : error C2011: “Office::MsoLineStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1051) : 参见“Office::MsoLineStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1061) : error C2011: “Office::MsoArrowheadStyle”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1061) : 参见“Office::MsoArrowheadStyle”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1072) : error C2011: “Office::MsoArrowheadWidth”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1072) : 参见“Office::MsoArrowheadWidth”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1080) : error C2011: “Office::MsoArrowheadLength”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1080) : 参见“Office::MsoArrowheadLength”的声明
1>e:\hbj\test3\test0722\test0722\debug\ksoapi.tlh(1088) : error C2011: “Office::MsoFillType”: “enum”类型重定义
1>        e:\hbj\test3\test0722\test0722\debug\mso.tlh(1088) : 参见“Office::MsoFillType”的声明

4.ksoapi.dll和mso.dll都用到了Office命名空间,必须重命名了,于是

#import "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\MSO.DLL" rename("RGB", "_RGB1")#import "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"#import "D:\Program Files\Microsoft Office\Office15\MSWORD.OLB" rename("ExitWindows", "_ExitWindows1"),rename("FindText", "_FindText1")#import "D:\Program Files (x86)\Kingsoft\WPS Office\9.1.0.4715\office6\ksoapi.dll" rename_namespace("WpsOffice") \    rename("RGB", "_RGB2"),rename("IAccessible", "_IAccessible2")#import "D:\Program Files (x86)\Kingsoft\WPS Office\9.1.0.4715\office6\wpsapi.dll" rename_namespace("WPS") \    rename("ExitWindows", "_ExitWindows2"),rename("FindText", "_FindText2")
编译通过

总结:

no_namespace属性

#import头文件中的类型库内容一般定义在一个名称空间里。名称空间的名称在原来IDL文件的library语句中指定。如果指定no_namespace属性,编译器就不会生成这个名称空间。

如果你想使用一个不同的名称空间,应代替使用rename_namespace属性。

参考:

http://technet.microsoft.com/zh-cn/library/8etzzkb6.aspx

http://blog.sina.com.cn/s/blog_570236f9010008yz.html

http://blog.csdn.net/dragoo1/article/details/38051083

0 0