[英]How to make C++ app switch between different MS office versions?
I have an old MFC tool to convert xls files to txt. 我有一个旧的MFC工具将xls文件转换为txt。 It is designed for some certain data structure and it's not easy to rewrite it with new framework (eg Qt).
它是为某些特定的数据结构而设计的,用新的框架(例如Qt)重写它并不容易。
The app works with excel and there is file 'Office.h', where office versions macro is defined: 该应用程序使用excel,并有文件'Office.h',其中定义了office版本宏:
// Office.h
//#define Uses_MSO97
//#define Uses_MSO2000
//#define Uses_MSO2002
//#define Uses_MSO2003
//#define Uses_MSO2007
#define Uses_MSO2010
The question is: how to make the app to define which MSO version is present at the computer and use it? 问题是:如何让应用程序定义计算机上存在哪个MSO版本并使用它?
I'd say, I have an access to source code. 我会说,我可以访问源代码。 The macro is used as:
该宏用作:
#ifdef Uses_MSO2007
#import "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE12\mso.dll" \
rename("DocumentProperties", "DocumentPropertiesXL") \
rename("RGB", "RBGXL")
#import "c:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA6\vbe6ext.olb"
#import "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" \
rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") \
rename("DocumentProperties", "DocumentPropertiesXL") \
rename("ReplaceText", "ReplaceTextXL") \
rename("CopyFile", "CopyFileXL") no_dual_interfaces
#endif
The first thing you should do is to extract your code to a .dll. 您应该做的第一件事是将代码提取到.dll。
Then, you could set your solution to compile a version of the dll for each Uses_MSOXXXX macro. 然后,您可以设置解决方案以编译每个Uses_MSOXXXX宏的dll版本。
In the application, you could use registry keys to determine the version of office installed, then dynamically load the dll related to the client's version of office. 在应用程序中,您可以使用注册表项来确定安装的Office版本,然后动态加载与客户端版本的office相关的dll。 (using LoadLibrary )
(使用LoadLibrary )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.