1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
int ExcelCls::ds_ta_function()
{
char *szVersion = new char[255];
version = GetVersion("Excel.Application",szVersion,255);
delete []szVersion;
}
int ExcelCls::GetVersion(LPCTSTR szApp, LPSTR szVersion, ULONG cSize)
{
CHAR szKey[128], szValueName[128];
HKEY hKey, hKey1;
int val = 0;
wsprintf(szKey, "%s", szApp);
LONG lRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, szKey, 0, KEY_ALL_ACCESS, &hKey);
if (lRet != ERROR_SUCCESS) {
ProgID is correct", MB_OK, 0);
return -1;
}
wsprintf(szValueName, "%s", "CurVer");
lRet = RegOpenKeyEx(hKey, szValueName, 0, KEY_ALL_ACCESS, &hKey1);
if (lRet != ERROR_SUCCESS) {
// Excel is registered, but no local server can be found!!!
return -1;
}
// Get the Version information
lRet = RegQueryValueEx(hKey1, NULL, NULL, NULL, (BYTE*)szVersion, &cSize);
// Close the registry keys
RegCloseKey(hKey1);
RegCloseKey(hKey);
// Error while querying for value
if (lRet != ERROR_SUCCESS)
return -1;
// Store the version number
CString x;
x = szVersion;
x.Find(".");
x = x.Right(2);
if (strncmp(x, ".6", 2) == 0)
{
// strcpy(szVersion, "Version 95");
val = -1;
return val;
}
else if (strncmp(x, ".8", 2) == 0)
{
// strcpy(szVersion, "Version 97");
val = 0;
return val;
}
else if (strncmp(x, ".9",2) == 0)
{
// strcpy(szVersion, "Version 2000");
val = 1;
return val;
}
else if (strncmp(x,"10",2) == 0)
{
// strcpy(szVersion, "Version 2002");
val = 2;
return val;
}
else if (strncmp(x,"11",2) == 0)
{
// strcpy(szVersion, "Version 2003");
val = 3;
return val;
}
else
{
val = -1;
return val;
// strcpy(szVersion, "Version unknown");
}
return TRUE;
} |
Partager