简体   繁体   中英

How to make C++ app switch between different MS office versions?

I have an old MFC tool to convert xls files to txt. It is designed for some certain data structure and it's not easy to rewrite it with new framework (eg Qt).

The app works with excel and there is file 'Office.h', where office versions macro is defined:

// 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?

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.

Then, you could set your solution to compile a version of the dll for each Uses_MSOXXXX macro.

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. (using LoadLibrary )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM