From: http://blog.csdn.net/lpc_china/article/details/18359145
Main principle: Query the Windows Registry for Microsoft Office software item values to determine the version.
Main Source:
Header file:
1 #pragmaOnce2#include <Windows.h>3#include <tchar.h>4 5 classcjudgeofficeversion6 {7 Public:8 cjudgeofficeversion ();9~cjudgeofficeversion ();Ten One Public: A BOOL judgeversion (out LPTSTR _lpversion, in DWORD _dwversionbufferlen); -};
Source:
1#include"JudgeOfficeVersion.h"2#include <strsafe.h>3 4 /*5 * Function Name: cjudgeofficeversion6 * Function Function: constructor function7 * Function parameter: none8 * function return: none9 * Function Note: noneTen * Author: Liu Peng Spring One */ A cjudgeofficeversion::cjudgeofficeversion () - { - the } - - /* - * Function Name: ~cjudgeofficeversion + * Function function: destructor - * Function parameter: none + * function return: none A * Function Note: none at * Author: Liu Peng Spring - */ -cjudgeofficeversion::~cjudgeofficeversion () - { - - } in - /* to * Function Name: judgeversion + * Function function: Judge version - * Function parameter: 1 character pointer; 2 pointer length; the * Function return: Judging State * * Function Note: Find CLSID with ProgID query the Office version information recorded in the server $ * This code is derived from:HTTP://SUPPORT.MICROSOFT.COM/KB/247985/ZH-CNPanax Notoginseng * Author: Liu Peng Spring - */ the BOOL cjudgeofficeversion::judgeversion (out LPTSTR _lpversion, in DWORD _dwversionbufferlen) + { A HKEY HKEY; the HKEY Hsubkey; +LONG LResult =0L; - $TCHAR szvaluename[ -] = {_t ("Curver")}; $TCHAR szkey[ -] = {_t ("Excel.Application")}; - -LResult =RegOpenKeyEx ( the HKEY_CLASSES_ROOT, - Szkey,Wuyi 0, the key_all_access, -&HKey Wu ); - if(Error_success! =LResult) { AboutMessageBox (NULL, _t ("Could not get CLSID from the ProgID, make sure ProgID is correct."), _t ("Tips"), MB_OK); $ returnFALSE; - } - -LResult =RegOpenKeyEx ( A HKey, + szValueName, the 0, - key_all_access, $&Hsubkey the ); the if(Error_success! =LResult) { theMessageBox (NULL, _t ("Excel is registered, but no local server can be found!"), _t ("Tips"), MB_OK); the returnFALSE; - } in theLResult = RegQueryValueEx (hsubkey, NULL, NULL, NULL, (LPBYTE) _lpversion, &_dwversionbufferlen); the About RegCloseKey (hsubkey); the RegCloseKey (HKey); the the if(Error_success! =LResult) { + returnFALSE; - } the BayiPtchar Pszversionnumber = _TCSRCHR (_lpversion, _t ('.')); thePtchar pversion = (Pszversionnumber +1); theINT nversion =_ttoi (pversion); - - ZeroMemory (_lpversion, _dwversionbufferlen); the Switch(nversion) the { the Case 0: the Case 1: - Case 2: the Case 3: the Case 5: theStringCchCopy (_lpversion, _dwversionbufferlen, _t ("Previous versions of Office 95"));94 Break; the Case 6: theStringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office")); the Break;98 Case 8: AboutStringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office")); - Break;101 Case 9:102StringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office"));103 Break;104 Case Ten: theStringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office XP"));106 Break;107 Case One:108StringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office 2003"));109 Break; the Case A:111StringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office")); the Break;113 Case -: the Case -: the Case the: theStringCchCopy (_lpversion, _dwversionbufferlen, _t ("Office"));117 Break;118 default:119StringCchCopy (_lpversion, _dwversionbufferlen, _t ("Version 2010 later")); - }121 122 returnTRUE;123}
* Note: This method is relatively simple and easy to implement.
C + + Judging Office Version-reproduced