c++ - Can I get a code page from a language preference? -


windows seems keep track of @ least 4 dimensions of "current locale": http://www.siao2.com/2005/02/01/364707.aspx

  • default user locale
  • default system locale
  • default user interface language
  • default input locale

my brain hurts trying keep track of hell 4 separate locale's useful for...

however, don't grok relationship between code page , locale (or licd, or language id), of appear different (e.g. japanese (japan) langid = 0x411 location code 1, code page japan 932).

how can configure our application use user's desired language default mbcs target when converting between unicode , narrow strings?

that say, used mbcs application. switched unicode. things work in english, fail in asian languages, apparently because windows conversion functions widechartomultibyte , multibytetowidechar take explicit code page (not locale id or language id), can set cp_acp (default ansi code page), don't appear have value "default user's default interface langage's code page".

i mean, convoluted twaddle. 4 separate dimensions of "current language", 3 different identifier types, (different) string-identifiers c library , c++ standard library.

in our previous mbcs builds, disk i/o , user i/o worked correctly: remained in default system locale (windows xp term: "language non-unicode programs"). now, in our unicode builds, tries use "c" locale, , file i/o fails transcode unicode user's locale, , vice verse.

we want have text files written out (when narrow) using current user's langauge's code page. , when read in, current user's language's code page should converted unicode.

help!!!

clarification: ideally use mui language code page rather os default code page. getacp() returns system default code page, unaware of function returns user's chosen mui language (which auto-reverts system default if no mui specified / installed).

if want able configure locale object use selected locale settings, should able this:

std::locale loc = std::locale(""); 

you can access current code page in windows using win32 ::getacp() function. here example implemented in string class append multi-byte characters unicode string:

void struni::append_mb(char const *buff, size_t buff_len) {     uint current_code_page = ::getacp();     int space_needed;       if(buff_len == 0)        return;     space_needed = ::multibytetowidechar(        current_code_page,        mb_precomposed | mb_err_invalid_chars,        buff,        buff_len,        0,        0);     if(space_needed > 0)     {        reserve(this->buff_len + space_needed + 1);        multibytetowidechar(           current_code_page,           mb_precomposed | mb_err_invalid_chars,           buff,           buff_len,           storage + this->buff_len,           space_needed);        this->buff_len += space_needed;        terminate();     } } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -