Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion of BSTR string to new character string

Status
Not open for further replies.

KarthikT

Programmer
Jan 23, 2006
1
0
0
US
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****

GlobalInterfacePtr->GetName(bstr, bstrTNamePtr, &retVal);

wcscpy (wstr1, *bstrTNamePtr);

char text2[20];

WideCharToMultiByte (CP_ACP, 0, wstr1, -1, text2, sizeof (text2), NULL, NULL);

**** Code END****

What I am doing in this code is getting a string value from the C#.NET to VC++ . The C# .NET sends the correct string value. When VC++ receives it, it comes up with a junk value for the string "Text2". I scripted this code with the help from MSDN. Dont know why I am geting the junk value. I guess the conversion to new character string is not done properly. This code was working two months back. I dug it out to polish it here and there. But, it would not work. I would apprecite if anyone could help me out here!!!

Thanks a much!

Karthik
 
What's the return value from WideCharToMultiByte()?
Have you tried other values other than CP_ACP?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top