HOWTO: Trapping Visual SourceSafe OLE errorsLast reviewed: October 28, 1997Article ID: Q175758 |
The information in this article applies to:
SUMMARYWhen writing an application that drives SourceSafe via OLE automation, you may want to trap the error codes defined in ssauterr.h. This file can be found at:
http://www.microsoft.com/SSAFE/download/ssauterr.hThis article describes how to trap these error codes from Visual Basic and Visual C++. NOTE: This cannot be done in C++ if you use the code generated by the Class Wizard to generate a wrapper for SSAPI.DLL.
MORE INFORMATION
Visual Basic CodeIn Visual Basic, the error code is returned as the HelpContext property of the Err object. An example of Visual Basic error handling code:
Private Sub DriveVss() Set oSSafe = CreateObject("SourceSafe") 'assume this succeeds On Error GoTo errlabel inipath = "c:\vss\srcsafe.ini" user = "FredA" pwrd = "TopHat" oSSafe.Open SrcSafeIni:= inipath, Username:= user, Password:= pwrd Set oProject = oSSafe.VSSItem("$/myproj") Exit Sub errlabel: errmsg = "Source: " & Err.Source & vbCrLf & _ "Error Number: " & Err.HelpContext & vbCrLf & _ "Please inform your SourceSafe Admin" MsgBox (errmsg) End Sub Visual C++ CodeIn Visual C++, the error code is a member of the HRESULT structure that is returned from the call to the automation method. The DriveVSS function below is based upon the code in the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q169928 TITLE : HOWTO: Open a SourceSafe Database with OLE Automation in C++where pVdb is a pointer to the IVSSDatabase interface. You will need to add the following:
#include <winerror.h> //for HRESULT_CODE #include <string.h> //for strcpy, strcat #include <stdlib.h> // for itoato the header files listed in Q169928.
void DriveVSS() { void ErrHand(HRESULT hr); IVSSItem *pIVSSItem; HRESULT hr; BSTR bstrPath = SysAllocString(L"c:\\vss\\srcsafe.ini"); BSTR bstrUName = SysAllocString(L"FredA"); BSTR bstrUPass = SysAllocString(L"TopHat"); BSTR bstrVSSSpec = SysAllocString(L"$/myproj"); if(!SUCCEEDED(hr = pVdb->Open(bstrPath,bstrUName, bstrUPass))) ErrHand(hr); else if(!SUCCEEDED(hr = pVdb->get_VSSItem(bstrVSSSpec,0,&pIVSSItem))) ErrHand(hr); } void ErrHand(HRESULT hr) { short sErrCode = HRESULT_CODE(hr); char cErrCode[6]; char strMessage[50]; strcpy(strMessage,"Error #: "); itoa(sErrCode, cErrCode, 10); strcat(strMessage, cErrCode); strcat(strMessage, "\n\n Please inform your SourceSafe Administrator"); MessageBox(NULL, strMessage, NULL, MB_OK); }(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by David de Groot, Microsoft Corporation Keywords : ssother ssvb ssvc Version : WINDOWS:5.0; WINNT:97 Platform : WINDOWS winnt Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |