Re: Convert LCID to ANSI locale string?
On Feb 1, 10:58 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
In my experience, CRT startup code sets up the locale to match the OS
user locale ( GetUserDefaultLCID ). It even goes as far as surfacing
manual overrides to number formats and such via localeconv - something
that can't be done by the program itself using public API only.
Are you saying this has not automatically happened in your application?
Yes, in my experience (as well as in my expectations) it does not:
-- output --
Am I missing something again? ;-)
Are you calling setlocale yourself at any point?
Sorry, I should have posted the complete example in the first place.
Here it is:
// grab the definition from the first post to make this work
void get_locale_string(TCHAR* locale, size_t size, LCID lcid =
main(int argc, char* argv)
if (argc != 2)
char const* filename = argv;
std::cerr << "open: " << filename << ": " << strerror(errno) <<
file << "test" << std::endl;
FILE* file = fopen(filename, "w");
The problem is that, while working perfectly with fopen(), it does not
work with std::ofstream unless I call setlocale explicitly as in
Since I have never ever seen LOCALE environment variable to be set
under Windows I guessed that WinAPI locale mechanism might be used to
obtain "correct" locale string based on the default locale id.
Well, you can look at setlocale implementation in CRT sources that ship
with MSVC. The interesting pieces are in getqloc.c. The code there does
essentially the inverse of what you are doing, using EnumSystemLocales
and GetLocaleInfo to find a locale where string representations of
language and country would match those passed to setlocale. So if your
goal is to deconstruct an LCID into a string that setlocale would
reconstruct back into the same LCID, I believe you are on the right
track. I'm not sure it's necessary to solve your real problem though.
This is exactly the point which confuses me a lot :-) Looks like I
need to sync myself both APIs (C setlocale and WinAPI SetLocale) each
time I want to deal with locales...