472,146 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to convert System::String to CString??

Hi

How do I convert a managed System::String to a CString. I need to handle
unicode characters ( Japan and Chinese ) as well as "normal" ANSI
characters.

I have tried the following

char* p =
(char*)System::Runtime::InteropServices::Marshal:: StringToHGlobalAnsi(
msg ).ToPointer();
CString str(p);

which works fine as long we are not dealing with Japanese. How do I handle
both situations??

Regards Morten

Nov 16 '05 #1
3 25244
Hi Morten,

Thanks posting in the group!

You can refer to the following KB article, maybe you can find good
resolution from it:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?id=311259

Hope that helps!
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Nov 16 '05 #2
Thanks :-)

Regards Morten
"Gary Chang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:gK**************@cpmsftngxa06.phx.gbl...
Hi Morten,

Thanks posting in the group!

You can refer to the following KB article, maybe you can find good
resolution from it:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?id=311259

Hope that helps!
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #3
Hi Morten,
How do I convert a managed System::String to a CString. I need to handle
unicode characters ( Japan and Chinese ) as well as "normal" ANSI
characters.

I have tried the following

char* p =
(char*)System::Runtime::InteropServices::Marshal:: StringToHGlobalAnsi(
msg ).ToPointer();
CString str(p);

which works fine as long we are not dealing with Japanese. How do I handle
both situations??


You'd probably need to stay in unicode (compiling your code for unicode,
instead of ANSI). Ohh, BTW, there's a CString constructor that already takes
a System::String* as an argument :)

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Peter Schmitz | last post: by
3 posts views Thread by Tim Mulholland | last post: by
15 posts views Thread by Yifan | last post: by
11 posts views Thread by Code[R] | last post: by
reply views Thread by Tommaso Caldarola | last post: by
14 posts views Thread by =?Utf-8?B?Sm9hY2hpbQ==?= | last post: by
1 post views Thread by AJ32 | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.