--
Regards,
Nish [VC++ MVP]
"Kueishiong Tu" <kst...@seed.net.tw> wrote in message
news:0b1101c37216$fdddbbc0$a301...@phx.gbl...
See: StringToHGlobalAnsi (System::Runtime::InteropServices::Marshal)
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclassstringtohglobala
nsitopic.asp
But conversion to ANSI is bad... because String is UNICODE... so if it
contains some unicode characters this might be lost.
Better convert to unicde: StringToHGlobalUni
or use PtrToStringChars (which is faster; if you do not need to modify the
string)
See also:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259
--
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp
> String* str = S"Hello world";
> char c = (char)str->Chars[0];
Well, that's one cast I'd stay away from, if you want your app to work when
"special" characters are in the string (remember that System::String is
UTF-16 encoded, while you are only handling 8-bit characters in char)
--
Tomas Restrepo
tom...@mvps.org
Kueishiong Tu
> I tried it and it worked. As a matter of fact, I need to
> convert the whole string. So I just put it in a loop.
As Tomas explained: You shouldn´t do that if you must handle other
characters than ANSI-characters.
Better Convert to w_chart or use some conversion routines:
<my post>
See: StringToHGlobalAnsi (System::Runtime::InteropServices::Marshal)
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclassstringtohgloba
la
nsitopic.asp
But conversion to ANSI is bad... because String is UNICODE... so if it
contains some unicode characters this might be lost.
Better convert to unicde: StringToHGlobalUni
or use PtrToStringChars (which is faster; if you do not need to modify
the
string)
See also:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259
</my post>
--
Greetings
Jochen
Do you need a memory-leak finder ?
--
Regards,
Nish [VC++ MVP]
"Tomas Restrepo (MVP)" <tom...@mvps.org> wrote in message
news:#UnXjpnc...@TK2MSFTNGP11.phx.gbl...