By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

convert a BSTR data type to std::string

P: n/a
Hello,

How can I convert a BSTR data type to std::string??? Thanks a much!

Karthik

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Karthik" <ka*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hello,

How can I convert a BSTR data type to std::string??? Thanks a much!

Karthik


Ask in a microsoft newsgroup. I believe BSTR is a microsoft-defined type.

(But, have you tried simply assigning from your BSTR variable to your
std::string variable, or creating a std::string with the BSTR as the
std::string's constructor's parameter?)

-Howard
Jul 23 '05 #2

P: n/a

"Karthik" <ka*******@gmail.com> schrieb im Newsbeitrag
news:11**********************@g43g2000cwa.googlegr oups.com...
How can I convert a BSTR data type to std::string??? Thanks a much!


A BSTR - if you are talking about the Microsoft thing - basically is a
unicode string. To convert it into an std::string you have to use functions
like wcstombs or WideCharToMultiByte. But you should better use std::wstring
instead of std::string, or you cannot convert all possible characters in a
BSTR.

HTH
Heinz
Jul 23 '05 #3

P: n/a
> How can I convert a BSTR data type to std::string??? Thanks a much!

Seems a BSTR is a double-byte string, so you won't be able to put it in
a std::string. Use std::wstring instead. Something like

void f(BSTR ms_str)
{
std::wstring ws(ms_str);
}

should work, but you would be better served in a microsoft newgroup.

Jonathan

Jul 23 '05 #4

P: n/a


Howard wrote:
"Karthik" <ka*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hello,

How can I convert a BSTR data type to std::string??? Thanks a much!

Karthik

Ask in a microsoft newsgroup. I believe BSTR is a microsoft-defined type.


That's a good suggestion.
(But, have you tried simply assigning from your BSTR variable to your
std::string variable, or creating a std::string with the BSTR as the
std::string's constructor's parameter?)


I'm guessing that it probably won't work, based on what I read here:

http://www.codeproject.com/string/bstrsproject1.asp

This may help the OP.

Brian

Jul 23 '05 #5

P: n/a
Karthik wrote:
How can I convert a BSTR data type to std::string??? Thanks a much!


#include <comdef.h>

std::string myString = _bstr_t (myBSTR);

Future BSTR questions belong on some other newsgroup blah blah blah...

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.