How to convert _bstr_t to CString

前端 未结 5 479
春和景丽
春和景丽 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 10:43

    If you compile for Unicode - just assign the encapsulated BSTR to the CString. If you compile for ANSI you'll have to use WideCharToMultiByte() for conversion.

    Also beware that the encapsulated BSTR can be null which corresponds to an empty string. If you don't take care of this your program will run into undefined behaviour.

提交回复
热议问题