简体   繁体   English

如何在不同的MS Office版本之间切换C ++应用程序?

[英]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.

相关问题 具有 C++ 接口的 C++ 动态库如何不破坏不同编译器版本之间的 ABI? - How can a C++ dynamic library with a C++ interface not break ABI between different compiler versions? C ++ —在类的不同模板版本之间进行转换的方法 - C++ — Method for Casting between different Templated versions of a class 如何在C ++中切换2个函数集? - How to switch between 2 function sets in C++? 我应该如何构建一个C ++应用程序以分发到不同版本的OS X / macOS? - How should I build a C++ app for distribution to different versions of OS X/macOS? 如何在未在C ++中安装ms office的系统中打开ms access数据库 - how to open ms access database in system which does not have ms office installed in c++ 不同版本的C ++库 - Different versions of C++ libraries 在C ++中的&lt;&lt;和&gt;&gt;之间运行时切换 - Runtime switch between << and >> in C++ 如何在c ++中透明地处理不同的协议版本? - How to handle different protocol versions transparently in c++? 如何在C ++字体库中支持不同的OpenGL版本/扩展 - How to support different OpenGL versions/extensions in C++ font library 如何在gcc版本之间正确切换? - How to properly switch between gcc versions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM