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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
chensuCommented:
Then use _bstr_t and its operator _bstr_t::char*.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eric07Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.