473,287 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

convert a BSTR data type to std::string

Hello,

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

Karthik

Jul 23 '05 #1
5 48565

"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

"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
> 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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
8
by: ppcdev | last post by:
Here's what I try : LPCTSTR tst = (LPCTSTR) (LPCWSTR) Marshal::StringToHGlobalUni(str); c:\MyNetPrj\Prj0001\stunt.cpp(244): error C2440: 'type cast' : cannot convert from 'System::IntPtr' to...
5
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** ...
3
by: babu17 | last post by:
hi, i have an asp page which creates a object using server.createobject and uses its method. example: set obj1= server.createobject("test.test") ' test is a dll tmp = obj1.method() ' it...
10
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char*...
2
by: Abhishek | last post by:
how to do convert a std::string to LPTSTR (chat *) datatype regards Abhishek
10
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's...
7
by: varsha.gadekar | last post by:
I want to convert the message of type RWCString to std::string type. How can we do this?
11
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.