Help on converting an ATL BSTR to be used in basic_string

I'm just learning ATL development.  I've created a simple project ( w/out the use of mfc so there isnt any CString support ) but I have a method

STDMETHODIMP CFileIO::OpenFile(OpenFileIO nHow, BSTR sFile, BSTR *sNewFile)


I would like to convert the BSTR sFile to a basic_string so that I can manipulate it properly, however I'm not sure how to do this.  I see so many types of conversion an not quite sure what to use.  There is _bstr_t, CComBSTR, etc.


I would like to convert it to a basic_string and then manipulate it, maybe append it with something then convert it back to a BSTR as *sNewFile

Thanks
eric07Asked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
Then use _bstr_t and its operator _bstr_t::char*.
0
 
stefanrCommented:
I.e.

#include <atlconv.h>
#include <string>

std::string str = W2CA(*sNewFile);

// Manipulate str...

::SysFreeString(*sNewFile);

*sNewFile = A2BSTR(str.c_str());
0
 
chensuCommented:
You can use CComBSTR or _bstr_t to manipulate it directly. Thus, you don't have to convert back and forth.

// BSTR sFile

CComBSTR bstrFile(sFile);

bstrFile.Append("abc");

*sNewFile = bstrFile.Copy();
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
eric07Author Commented:
But I thought basic_string had more string methods to manipulate the data.  And that is why I wanted to try and figure out how to confvert a BSTR to a basic_string.


THanks
0
 
eric07Author Commented:
But I thought basic_string had more string methods to manipulate the data.  And that is why I wanted to try and figure out how to confvert a BSTR to a basic_string.


THanks
0
 
eric07Author Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.