dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Convert string to BSTR

  1. #1
    Join Date
    May 2015
    Posts
    213

    Convert string to BSTR

    I have a function
    Code:
    func(BSTR * path)
    {
    
    // From path paramter I use the path. 
    
    //Now I generate some lets say list of names separated by newline
    
    string output = "Bob\n Rob \n Lilly \n";
    
    
    // Now client wants the path to be modified with the output
    
    	SysFreeString(*path);
    	*path= SysAllocStringByteLen(output.c_str(), output.size());
    
    }
    Is the last two lines correct. Somehow testing doesnot seems ok !

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Convert string to BSTR

    Could you use _bstr_t Class rather than the plain BSTR?
    Then you would not care about SysFreeString/SysAllocString...
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    213

    Re: Convert string to BSTR

    Thanks a lot Victor, but this is client interface and I cannot change

  4. #4
    Join Date
    May 2015
    Posts
    213

    Re: Convert string to BSTR

    can some windows experts help me with this please.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,146

    Re: Convert string to BSTR

    Quote Originally Posted by pdk5 View Post
    Thanks a lot Victor, but this is client interface and I cannot change
    Sure, the interface can't change but you can do what you like internally.

    Code:
    func(BSTR* path)
    {
      _bstr_t myPath(path);
    
     // myPath has access to all of _bstr_t methods. happy, happy, happy
    }

  6. #6
    Join Date
    May 2015
    Posts
    213

    Re: Convert string to BSTR

    Thanks I tried to convert the string into wstring. Then copied that back to parameter to be passed back to interface. This now worked.
    May be I;ll try your suggestion also ..Thankyou again for commenting and giving inputs

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)