Re: get wide character and multibyte character value
"George" <George@discussions.microsoft.com> ha scritto nel messaggio
news:B919845F-F979-40C5-A2D8-FDDEDB8A3FE2@microsoft.com...
What is the differences between CP_ACP and CP_UTF8? I think CP_ACP means
system default code page and may be different from CP_UTF8? Right?
As Igor wrote, they are very different.
For example, the euro sign [I don't know if you can see it in this post, but
here it is in Outlook Express: ? ] is represented by these three different
bytes sequences:
* Unicode UTF-16:
0xAC
0x20
* Unicode UTF-8: (CP_UTF8)
0xE2
0x82
0xAC
* CP_ACP on my system (Italian Windows XP)
0x80
As you can see, CP_ACP and CP_UTF8 are different.
I see no reason to use CP_ACP in these days... IMHO you should always
consider Unicode (UTF-16 is good for processing inside Windows applications;
UTF-8 is good for storing text outside the app boundaries).
You can also read more details about CP_ACP and code page values in MSDN
documentation of ::WideCharToMultiByte, here:
WideCharToMultiByte
http://msdn2.microsoft.com/en-us/library/ms776420(VS.85).aspx
<cite>
[Value]
CP_ACP:
The current system Windows ANSI code page. This value can be different on
different computers, even on the same network. It can be changed on the same
computer, leading to stored data becoming irrecoverably corrupted. This
value is only intended for temporary use and permanent storage should be
done using UTF-16 or UTF-8 if possible.
</cite>
Moreover, you may try experimenting yourself with simple Win32 C++ program,
containing simple statements like this (I hope Outlook Express does not
"scramble" my post as it did in a previous thread in this same newsgroup
recently)
<code>
BYTE utf16[] = { 0xAC, 0x20, 0x00, 0x00 };
::MessageBoxW( NULL, (LPCWSTR)utf16, L"Euro", MB_OK );
BYTE utf8[100];
::WideCharToMultiByte( CP_UTF8, 0, (LPCWSTR)utf16, -1, (LPSTR)utf8,
sizeof(utf8), NULL, NULL );
BYTE acp[100];
::WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)utf16, -1, (LPSTR)acp,
sizeof(acp), NULL, NULL );
</code>
You can use Visual Studio IDE to inspect the content of those byte arrays.
Giovanni