How to convert _bstr_t to CString

前端 未结 5 534
春和景丽
春和景丽 2021-01-17 10:41

I have a _bstr_t variable bstrErr and I am having a CString variable csError. How do I set the value which come in

5条回答
  •  感动是毒
    2021-01-17 11:03

    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.

提交回复
热议问题