環境: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