multibyte - C/C++ I18N mbstowcs question -


I am working on internationalization of input for a C / C + + application I currently have a multi-byte string An issue has been raised to convert the wide character string from.

The code should be cross-platform compatible, so I am using mbstowcs and wcstombs as much as possible.

I am currently working on a WIN32 machine and I have set locale in non-English locale (Japanese).

When I try to change a multibyte character string, I start having some conversion problems.

Here is an example of code:

  Int main (int arc, four ** argv) {wchar_t * wcsVal = NULL; Char * mbsVal = NULL; / * Receive the current code page; In my case 932, only Windows * / TCHAR Sz code runs on page [10]; Int cch = GetLocaleInfo (GetSystemDefaultLCID), LOCALE_IDEFAULTANSICODEPAGE, szCodePage, sizeof (szCodePage)); / * Verified locale is set / / (Setocolokel (LC_TCPE, "") == 0) {fprintf (stderr, "Failed to set locale \ n"); Return 1; } MbsVal = argv [1]; / * Validate multibyte string and convert to wide characters * / int size = mbstowcs (NULL, mbsVal, 0); If (size == -1) {printf ("invalid multibeat \ n"); Return 1; } WcsVal = (wchar_t *) maulok (wchar_t) * (size + 1)); If (wcsVal == faucet) {printf ("memory issue \ n"); Return 1; } Mbstowcs (wcsVal, szVal, size + 1); Wprintf (L "% ls \ n", wcsVal); Return 0; }  

At the end of the execution, the converting data is not included in the expanded character string. I believe there is a problem with the code page settings, because when I use Multibyte Toowword and the current code page

EX: MultiByteToWideChar (CP_ACP, 0, mbsVal, -1, wcsVal, Size + 1); In place of the Mbstowcs call, the conversion is successful.

My question is how do I use generic MBSTOX calls instead of Tiny Basic BitToWidder calls?

If you print the string returned by setlocale () what you get? It indicates which location is actually set, which can not be the one you expected.

The default locale selected for the " on Windows, " the user-default ANSI code page from the operating system " probably it Current ANSI code is a different animal for the page?


Comments