How to convert _bstr_t to CString

CString has contructors and assignment operators for both LPCSTR and LPCWSTR, so there is never a need to call WideCharToMultiByte, and you can't get the casting wrong in unicode or non-unicode mode.

You can just assign the string this way:

csError = bstrErr.GetBSTR();

Or use the constructor CString csError( bstrErr.GetBSTR() );

I'm using GetBSTR. It's the same thing as casting bstrErr with (LPCWSTR), but I prefer it for legibility.


Is it not possible just to cast it:

_bstr_t b("Steve");
CString cs;
cs = (LPCTSTR) b;

I think this should work when the project is Unicode.