Microsoft KB Archive/248194: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - """ to """)
 
(2 intermediate revisions by the same user not shown)
Line 52: Line 52:
== RESOLUTION ==
== RESOLUTION ==


Instead of checking the HRESULT or whether the IVSSItem is not null, check the '''get_VersionNumber''' after calling '''get_Version'''. Compare the version numbers to make sure the version is valid. For example, place the following code inside the pVdb-&gt;get_VSSItem '''if''' statement:
Instead of checking the HRESULT or whether the IVSSItem is not null, check the '''get_VersionNumber''' after calling '''get_Version'''. Compare the version numbers to make sure the version is valid. For example, place the following code inside the pVdb->get_VSSItem '''if''' statement:
<pre class="codesample">// Used to store the latest version number of the item
<pre class="codesample">// Used to store the latest version number of the item
long originalnumber, num;
long originalnumber, num;


// Store the latest version number of the item
// Store the latest version number of the item
vssi-&gt;get_VersionNumber(&amp;originalnumber);
vssi->get_VersionNumber(&originalnumber);


// Get the version at the label (this label will fail)
// Get the version at the label (this label will fail)
CComVariant varLabel = -51;
CComVariant varLabel = -51;
vssi-&gt;get_Version(varLabel, &amp;vx);
vssi->get_Version(varLabel, &vx);


// Get the version number of the returned item
// Get the version number of the returned item
vx-&gt;get_VersionNumber(&amp;num);
vx->get_VersionNumber(&num);


// Compare the versions and see if the item is valid
// Compare the versions and see if the item is valid
if ( num &gt; 0 &amp;&amp; num <= originalnumber )
if ( num > 0 && num <= originalnumber )
   printf(&quot;Valid label.&quot;);
   printf("Valid label.");


// Release the item
// Release the item
vx-&gt;Release();</pre>
vx->Release();</pre>


</div>
</div>
Line 78: Line 78:
== STATUS ==
== STATUS ==


Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.


</div>
</div>
Line 97: Line 97:


</div>
</div>
<pre class="codesample">#include <atlbase.h&gt;
<pre class="codesample">#include <atlbase.h>
#include <comdef.h&gt;
#include <comdef.h>
#include <initguid.h&gt;
#include <initguid.h>
#include &quot;ssauto.h&quot;
#include "ssauto.h"


int main ()
int main ()
Line 107: Line 107:
   IClassFactory *pClf;
   IClassFactory *pClf;
   IVSSDatabase *pVdb;
   IVSSDatabase *pVdb;
   BSTR bstrPath = SysAllocString(L&quot;c:\\Program Files\\Microsoft Visual Studio\\Common\\VSS\\srcsafe.ini&quot;);
   BSTR bstrPath = SysAllocString(L"c:\\Program Files\\Microsoft Visual Studio\\Common\\VSS\\srcsafe.ini");
   BSTR bstrUName = SysAllocString(L&quot;guest&quot;);
   BSTR bstrUName = SysAllocString(L"guest");
   BSTR bstrUPass = SysAllocString(L&quot;&quot;);
   BSTR bstrUPass = SysAllocString(L"");


   CoInitialize(0);
   CoInitialize(0);
   if(S_OK == CLSIDFromProgID(L&quot;SourceSafe&quot;, &amp;clsid ))
   if(S_OK == CLSIDFromProgID(L"SourceSafe", &clsid ))
   {
   {
       if(S_OK == CoGetClassObject( clsid, CLSCTX_ALL, NULL,
       if(S_OK == CoGetClassObject( clsid, CLSCTX_ALL, NULL,
         IID_IClassFactory, (void**)&amp;pClf ))
         IID_IClassFactory, (void**)&pClf ))
       {
       {
         if(S_OK == pClf-&gt;CreateInstance( NULL, IID_IVSSDatabase,
         if(S_OK == pClf->CreateInstance( NULL, IID_IVSSDatabase,
             (void **) &amp;pVdb ))
             (void **) &pVdb ))
         {
         {
             if(S_OK == pVdb-&gt;Open(bstrPath, bstrUName, bstrUPass))
             if(S_OK == pVdb->Open(bstrPath, bstrUName, bstrUPass))
             {
             {
               // Get the root project
               // Get the root project
               BSTR bstrName = SysAllocString(L&quot;$/&quot;);
               BSTR bstrName = SysAllocString(L"$/");
               IVSSItem *vx;
               IVSSItem *vx;
               IVSSItem *vssi;
               IVSSItem *vssi;


               if( S_OK == pVdb-&gt;get_VSSItem(bstrName, FALSE, &amp;vssi) )
               if( S_OK == pVdb->get_VSSItem(bstrName, FALSE, &vssi) )
               {
               {
                   // Get the version at the label (this label should fail)
                   // Get the version at the label (this label should fail)
                   CComVariant varLabel = -51;
                   CComVariant varLabel = -51;
                   if( S_OK == vssi-&gt;get_Version(varLabel, &amp;vx) )
                   if( S_OK == vssi->get_Version(varLabel, &vx) )
                   {
                   {
                     // This prints out even though the label in invalid
                     // This prints out even though the label in invalid
                     printf(&quot;Should not be here.&quot;);
                     printf("Should not be here.");


                     vx-&gt;Release();
                     vx->Release();
                   }
                   }


                   vssi-&gt;Release();
                   vssi->Release();
               }
               }


Line 145: Line 145:
             }
             }


             pVdb-&gt;Release();
             pVdb->Release();
         }
         }


         pClf-&gt;Release();
         pClf->Release();
       }
       }
   }
   }

Latest revision as of 13:51, 21 July 2020

Article ID: 248194

Article Last Modified on 7/20/2005



APPLIES TO

  • Microsoft Visual SourceSafe 5.0 Standard Edition
  • Microsoft Visual SourceSafe 6.0 Standard Edition



This article was previously published under Q248194

SYMPTOMS

When trying to get a specific version of a file or project, the get_Version function returns successfully and has a valid item even if that item does not exist in the database.

RESOLUTION

Instead of checking the HRESULT or whether the IVSSItem is not null, check the get_VersionNumber after calling get_Version. Compare the version numbers to make sure the version is valid. For example, place the following code inside the pVdb->get_VSSItem if statement:

// Used to store the latest version number of the item
long originalnumber, num;

// Store the latest version number of the item
vssi->get_VersionNumber(&originalnumber);

// Get the version at the label (this label will fail)
CComVariant varLabel = -51;
vssi->get_Version(varLabel, &vx);

// Get the version number of the returned item
vx->get_VersionNumber(&num);

// Compare the versions and see if the item is valid
if ( num > 0 && num <= originalnumber )
   printf("Valid label.");

// Release the item
vx->Release();

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Create a Win32 Console Application in Microsoft Visual C++.
  2. Add the following code to the project.

    Note This is the same code as in the following Microsoft Knowledge Base Article:

    169927 How to get history using SourceSafe OLE automation in C++

    #include <atlbase.h>
    #include <comdef.h>
    #include <initguid.h>
    #include "ssauto.h"
    
    int main ()
    {
       CLSID clsid;
       IClassFactory *pClf;
       IVSSDatabase *pVdb;
       BSTR bstrPath = SysAllocString(L"c:\\Program Files\\Microsoft Visual Studio\\Common\\VSS\\srcsafe.ini");
       BSTR bstrUName = SysAllocString(L"guest");
       BSTR bstrUPass = SysAllocString(L"");
    
       CoInitialize(0);
       if(S_OK == CLSIDFromProgID(L"SourceSafe", &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))
                {
                   // Get the root project
                   BSTR bstrName = SysAllocString(L"$/");
                   IVSSItem *vx;
                   IVSSItem *vssi;
    
                   if( S_OK == pVdb->get_VSSItem(bstrName, FALSE, &vssi) )
                   {
                      // Get the version at the label (this label should fail)
                      CComVariant varLabel = -51;
                      if( S_OK == vssi->get_Version(varLabel, &vx) )
                      {
                         // This prints out even though the label in invalid
                         printf("Should not be here.");
    
                         vx->Release();
                      }
    
                      vssi->Release();
                   }
    
                   SysFreeString(bstrName);
                }
    
                pVdb->Release();
             }
    
             pClf->Release();
          }
       }
    
       CoUninitialize();
    
       SysFreeString(bstrPath);
       SysFreeString(bstrUName);
       SysFreeString(bstrUPass);
       return 0;
    }
  3. Download and add the ssauto.h header file that is used to integrate with Visual SourceSafe from the following Microsoft Web site:
  4. Run the program.


REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

196197 You receive an error message when you get a file from a project label by using OLE automation



Additional query words: ssauto

Keywords: kbbug kbnofix kbautomation KB248194