Tuesday, December 4, 2007

Microsoft Visual Source Safe Client VC++

Microsoft Visual Source Safe Client VC++

// Be sure to link with the following libraries:

// user32.lib uuid.lib oleaut32.lib ole32.lib

#define INITGUID

#include <windows.h>
#include <ocidl.h>
#include "ssauto.h"

int
main ()
{
      CLSID clsid;
      IClassFactory *pClf;
      IVSSDatabase *pVdb;
      BSTR bstrPath = SysAllocString(L"c:\\VSSclient\\srcsafe.ini");
      BSTR bstrUName = SysAllocString(L"guest");
      BSTR bstrUPass = SysAllocString(L"");

      CoInitialize(0);
      if(S_OK == CLSIDFromProgID(L"SourceSafe", &amp;clsid ))
      {
            if(S_OK == CoGetClassObject( clsid, CLSCTX_ALL, NULL,
                  IID_IClassFactory, (void**)&pClf ))
            {
                  if(S_OK == pClf->CreateInstance( NULL, IID_IVSSDatabase,
                        (void **) &pVdb ))
                  {
                        if(S_OK == pVdb->Open(bstrPath, bstrUName, bstrUPass))
                        {
                              //Database Successfully Opened!
                              //Add code here to use the open database.
                        }
                        pVdb->Release();
                  }
                  pClf->Release();
            }
      }
      CoUninitialize();
      SysFreeString(bstrPath);
      SysFreeString(bstrUName);
      SysFreeString(bstrUPass);
      return 0;
}

The header file ssauto.h can download from http://msdn2.microsoft.com/hi-in/vstudio/aa700903(en-us).aspx

 

No comments: