Example: Issuing a cleartool command (Visual C++)

#include <iostream.h>  
#include <atlbase.h>

#import <ccauto.dll> named_guids  
using namespace ClearCase;

int main()
{

   // Get ClearCase Interface
   CComBSTR output;

   // Initialize COM Library
   CoInitialize(NULL);

   try 
   {
      // Create the top-level ClearTool object
      IClearToolPtr pIClearTool = IClearToolPtr(CLSID_ClearTool);

      // Issue a ClearTool command
      output.Append(pIClearTool->CmdExec(L"pwv"));

      // Print out the results
      USES_CONVERSION; 
      if ( output.Length() >= 1 )
           cout << (((BSTR)output != 0) ? OLE2A(output) : "<none>")
           << "\n";
   }
   // Catch any COM errors thrown
   catch (_com_error& cerror)
   {
      cout << cerror.Description();
      cout << cerror.Error() << "\n";
   }
   return 0;
}

Feedback