Possible Duplicates:
Which is better code for converting BSTR parameters to ANSI in C/C++?
How to convert char * to BSTR?
How I can convert BSTR to const char*?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
BSTRis actually aWCHAR*with a length prefix. TheBSTRvalue points to the beginning of the string, not to the length prefix (which is stored in the bytes just “before” the location pointed to by theBSTR).In other words, you can treat a
BSTRas though it is aconst WCHAR*. No conversion necessary.So your question is really: “How can I convert a Unicode string (
WCHAR*) to achar*?” and the answer is to use the::WideCharToMultiByteAPI function as explained here. Or, if you are using MFC/ATL in your application, use the ATL and MFC Conversion Macros.