1 Reply Latest reply on Mar 21, 2017 6:11 PM by Baldur Steingrimsson

    How to convert from const chart* to CComBSTR when calling swDocMgr->GetDocument()

    Baldur Steingrimsson

      I am trying to resolve a pesky problem involving conversion from const char* to CComBSTR. I am apparently not using quite the right format, when passing the input files to the function

      hres = swDocMgr->GetDocument( docPath, swDmDocumentAssembly, VARIANT_TRUE, &res, &swDoc );

       

      // http://stackoverflow.com/questions/606075/how-to-convert-char-to-bstr

      // It appears the input files cannot be opened, due to some compiler specific conversion from char* to bstr:

      CComBSTR docPath = filenamePtr;                          // filenamePtr is of type const char*

      // How should I revise the statement above?

      cerr << swDocMgr;

      cerr << filenamePtr;

      cerr << docPath;

      cerr << swDmDocumentAssembly;

      cerr << "hres: " << hres << ", S_OK = " << S_OK << ", res: " << res << ", swDoc: " << swDoc;

      hres = swDocMgr->GetDocument( docPath, swDmDocumentAssembly, VARIANT_TRUE,  &res, &swDoc );

      cerr << swDocMgr;

      cerr << filenamePtr;

      cerr << docPath;

      cerr << swDmDocumentAssembly;

      cerr << "hres: " << hres << ", S_OK = " << S_OK << ", res: " << res << ", swDoc: " << swDoc;

       

      The corresponding output typically looks like this:

       

      0x975eb2c

      D:/Baldur_Imagars_19june2016/Imagars LLC - Automatic Image Recognition/Collaboration - Portland State Univ/Ecosystem Evaluations/Kart2 team - Spring 2016/Capstone Stand Final AssemblyB/ME 492 Stand Hitch Connection.SLDASM

      0xcbfc6cc

      0

      hres: 0 , S_OK = 0 , res: 4 , swDoc: 0x0

      0x975eb2c

      D:/Baldur_Imagars_19june2016/Imagars LLC - Automatic Image Recognition/Collaboration - Portland State Univ/Ecosystem Evaluations/Kart2 team - Spring 2016/Capstone Stand Final AssemblyB/ME 492 Stand Hitch Connection.SLDASM

      0xcbfc6cc

      0

      hres: -2147221230 , S_OK = 0 , res: 4 , swDoc: 0x0

        • Re: How to convert from const chart* to CComBSTR when calling swDocMgr->GetDocument()
          Baldur Steingrimsson

          Update

          I received the same type of response, when using the following

             CComBSTR docPath( "D:\\Baldur_Imagars_19june2016\\Imagars LLC - Automatic Image Recognition\\Collaboration - Portland State Univ\\Ecosystem Evaluations\\Kart2 team - Spring 2016\\Capstone Stand Final AssemblyB\\5-5 in Bolt.sldprt" );

           

          What perplexes me is the following:

          For a simple Visual Studio sample program, the same input file, with the same license key and input arguments resulted in

          hres = swDocMgr->GetDocument( docPath, swDmDocumentAssembly, VARIANT_TRUE,  &res, &swDoc );

          producing meaningful pointer (non-NULL) for swDoc.