Skip to content

Latest commit

 

History

History

Q175758

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
layout title permalink
page
Q175758: HOWTO: Trap Visual SourceSafe OLE Errors
/kb/175/Q175758/

Q175758: HOWTO: Trap Visual SourceSafe OLE Errors

{% raw %}

Article: Q175758
Product(s): Microsoft SourceSafe
Version(s): 
Operating System(s): 
Keyword(s): kbinterop kbSSafe500 kbSSafe600 kbVS97
Last Modified: 03-MAY-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual SourceSafe for Windows, versions 5.0, 6.0 
- Microsoft Visual Studio 97 
-------------------------------------------------------------------------------

SUMMARY
=======

When writing an application that drives SourceSafe via OLE automation, you may
want to trap the error codes defined in the ssauterr.h file. Click the link to
'VC++ Error Header File' that you find at the following Web site:

  http://msdn.microsoft.com/ssafe/downloads/samples.asp

This 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 Code
-----------------

In 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++ Code
---------------

In 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:

  Q169928 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 itoa

to 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


Additional query words:

======================================================================
Keywords          : kbinterop kbSSafe500 kbSSafe600 kbVS97 
Technology        : kbVSsearch kbSSafeSearch kbAudDeveloper kbSSafe600 kbSSafe500 kbVS97 kbVS97Search
Issue type        : kbhowto

=============================================================================

{% endraw %}