Anyone know how to convert BSTR to char* ?
Update: I tried to do this, but don’t know if it is right or wrong.
char *p= _com_util::ConvertBSTRToString(URL->bstrVal);
strcpy(testDest,p );
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.
Your code is okay.
ConvertBSTRToStringdoes just that. As for thestrcpy,testDestneeds to be large enough to hold the string pointed to byp. Note that since ConvertBSTRToString allocates a new string you will need to free it somewhere down the line. Once you are done make sure you do:A couple of caveats though (as you can see from
BSTRdocumentation on MSDN):So, your
strcpymay not always work as expected.