Article ID: 201431
Article Last Modified on 7/15/2004
169928 How To Open a SourceSafe Database with OLE Automation in C++
// This path needs to point to the ssapi for the 6.0 version of // SourceSafe (version 8169) #import "C:\Visual Studio\Vss\Win32\ssapi.dll"
// This path needs to point to the ssapi for the 5.0 version of
// SourceSafe (version 2218-2222)
#import "C:\DevStudio\Vss\Win32\ssapi.dll" rename_namespace("vss5")
Then, you can just test them with:
// version was initialized already by calling -
// version = checker.checkVersion(); where checker is class Check
if (version == 5) {
using namespace vss5;
.... // all your SourceSafe 5 commands go here.
} else {
.... // all your SourceSafe 6 commands go here.
}
// CCheck::checkVersion returns:
// -1 on error
// 5 for VSS version 5.0
// 6 for VSS versions later than 5.0
#include <windows.h>
class CCheck
{
public:
int checkVersion();
private:
LPTSTR GetRegistryInfo();
TCHAR m_szVSSDir[MAX_PATH];
};
LPTSTR CCheck::GetRegistryInfo()
{
m_szVSSDir[0] = '\0';
// Find the ssapi.dll registry key.
HKEY hclass;
if (RegOpenKeyEx(HKEY_CLASSES_ROOT,
"CLSID",
0,
KEY_QUERY_VALUE,
&hclass) == ERROR_SUCCESS) {
HKEY hkey;
if (RegOpenKeyEx(hclass,
"{783CD4E4-9D54-11CF-B8EE-00608CC9A71F}",
0,
KEY_QUERY_VALUE,
&hkey) == ERROR_SUCCESS) {
HKEY hproc;
if (RegOpenKeyEx(hkey,
"InprocServer32",
0,
KEY_QUERY_VALUE,
&hproc) == ERROR_SUCCESS) {
DWORD dwType = 0;
DWORD dwSize = sizeof(m_szVSSDir);
RegQueryValueEx(hproc,
"",
NULL,
&dwType,
(LPBYTE)m_szVSSDir,
&dwSize);
RegCloseKey(hproc);
}
RegCloseKey(hkey);
}
RegCloseKey(hclass);
}
return m_szVSSDir;
}
int CCheck::checkVersion()
{
LPTSTR szPath;
DWORD dwVerHnd;
DWORD dwVerInfoSize;
char szFullPath[MAX_PATH+1];
long resMOld = 327680;
long resM;
int ret = -1;
szPath = GetRegistryInfo();
strcpy(szFullPath, szPath);
dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
if (dwVerInfoSize) {
// If we were able to get the information, process it:
HANDLE hMem;
LPVOID lpvMem;
BOOL fRet;
UINT cchVer = 0;
VS_FIXEDFILEINFO *vInfo;
hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem = GlobalLock(hMem);
GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
fRet = VerQueryValue(lpvMem, TEXT("\\"),
(LPVOID*)&vInfo, &cchVer);
if (fRet && cchVer && vInfo) {
resM = vInfo->dwFileVersionMS;
if (resMOld >= resM) ret = 5;
else ret = 6;
}
GlobalUnlock(hMem);
GlobalFree(hMem);
}
return ret;
}
169928 How To Open a SourceSafe Database with OLE Automation in C++
Visual SourceSafe OLE Automation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvss/html/msdn_vssole.asp
Visual SourceSafe 6.0 Automation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvss/html/vssauto.asp
Keywords: kbhowto kbautomation KB201431