473,388 Members | 1,177 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,388 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 25483
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Schmitz | last post by:
Hi, is there any way to convert a managed System::String var to a BYTE pointer (BYTE*)? Thanks a lot Peter
3
by: Tim Mulholland | last post by:
How can i (using Managed C++) convert a System::String object containing basic text into a char* object? Thanks in advance, Tim
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
1
by: SteveK | last post by:
Trying to wrap an unmanaged class. Here is the function I'm trying to wrap: bool Init(PCSTR filename, PCSTR username, PCSTR password, PCSTR working); In my managed C++ class, I have a method...
11
by: Code[R] | last post by:
hello all, i've a problem :s i've tried to convert a "system::string" (a textbox) to an "int" but i have only found a function to convert system::string to char and char to int :s : ...
0
by: Tommaso Caldarola | last post by:
I have a custom collection of custom objects. I bind a DataGrid with collection1, a property of custom object is a ReferenceType (another custom object). For that property in the datagrid I...
2
by: sovarschizsuzsa | last post by:
Hy! I have written a MC++ wrapper DLL file for use in a C# project. This wrapper DLL is built on a C DLL. I have the following functions in the C DLL: int First(char* a1, char* a2, void* *a3,...
14
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have seen the following function to convert from a System::String^ to a const wchar_t*. I would like to get a LPCTSTR and AFAIK LPCTSTR is equal to const wchar_t*. Then it should all work right?...
1
by: AJ32 | last post by:
Hi, I am writting a program in visual c++ expres that takes user input and sends it to files, I am using a text box to get the input. The problem is, that I cannot use a "system string" when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.