=?Utf-8?B?SGVzc2U=?= wrote:
> Does Marshal.StringToHGlobalAnsi convert System.String to multibyte
> strings if necessary (if the System.String contains non-ANSI
> characters), or does it only convert ansi strings?
It converts to MBCS.
See: What is an ANSI string?
http://blog.kalmbachnet.de/?postid=19
> If it converts UNICODE characters to appropriate multibyte characters,
> what code page does it use for the conversion? Is it the operating
> system (Windows) code page (i.e. on Japanese windows, will it use the
> Japanese code page)?
I think they use "CP_ACP" (but I am not sure.. maybe I will dig into it...)

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jochen Kalmbach - 20 Oct 2004 07:05 GMT
> I think they use "CP_ACP" (but I am not sure.. maybe I will dig into
> it...)
I looked at it:
It is internally calling "WideCharToMultiByte" with codepage = CP_ACP
The codepage is hardcoded in the source of
"mscorwks!ML_CSTR_C2N_SR::DoConversion"
If you need a different codepade you could use the following code:
<code>
System::String *mstr = S"Hello world!";
char *ustr;
unsigned char c __gc[] =
System::Text::Encoding::GetEncoding(1252)->GetBytes(mstr);
unsigned char __pin*cc = &c[0];
ustr = new char[c->get_Length()+1];
strcpy(ustr, (char*) cc);
// now do something with the converted string
delete [] ustr;
</code>

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Hesse - 20 Oct 2004 16:49 GMT
Thanks Jochen! That answered my questions!
> > I think they use "CP_ACP" (but I am not sure.. maybe I will dig into
> > it...)
[quoted text clipped - 21 lines]
> delete [] ustr;
> </code>
Hesse - 20 Oct 2004 18:17 GMT
Hi,
Does Marshal.PtrToStringAnsi do the exact reverse of
Marshal.StringToHGlobalAnsi, that is, does it call MultiByteToWideChar with
the CP_ACP code page?
Thanks!
> > I think they use "CP_ACP" (but I am not sure.. maybe I will dig into
> > it...)
[quoted text clipped - 21 lines]
> delete [] ustr;
> </code>
Jochen Kalmbach - 20 Oct 2004 18:22 GMT
Hi =?Utf-8?B?SGVzc2U=?=,
> Does Marshal.PtrToStringAnsi do the exact reverse of
> Marshal.StringToHGlobalAnsi, that is, does it call MultiByteToWideChar
> with the CP_ACP code page?
I have not verified, but according to the doc: yes.

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/