There are multiple errors within in your code.
The first is that you are using ANSI strings which will fail when having a Unicode build because that will return Unicode strings. Some info values are only provided as Unicode strings so that these will always fail.
The second error is initialising the global object
customFormatConst
with local data. The structure contains pointers to strings which are set to local buffers that go out of scope when leaving the function.
See also the
GetLocaleInfo function (Windows)[
^] (or use
GetLocaleInfoEx function (Windows)[
^]).
So you should use something like this:
NUMBERFMT customFormatConst;
TCHAR thousandSep[10];
TCHAR infoBuf[128];
status = GetLocaleInfo(lcid, LOCALE_IDIGITS, infoBuf, sizeof(infoBuf) / sizeof(TCHAR));
defDigits = _tstoi(infoBuf);
status = GetLocaleInfo(lcid, LOCALE_STHOUSAND, thousandSep, sizeof(thousandSep) / sizeof(TCHAR));
customFormat->lpThousandSep = thousandSep;
if (customFormat)
customFormatConst = *customFormat;
[EDIT]
If you want to specify the locale decimal point for the C standard
printf
functions there is a much simpler solution (especially when this should be applied to the whole application and not be changed multiple times).
Then call
setlocale, _wsetlocale[
^] at program start (
main
,
InitInstance
). To use the default locale settings for the user use
setlocale(LC_ALL, "");
To set the code page for a know
LCID
use
char loc[16] = ".ACP";
::GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE, loc + 1, 15);
setlocale(LC_ALL, loc);
Note that the above changes all locale settings including dates, times, and collation order. If you only want to change the behaviour for numeric values use
LC_NUMERIC
isntead of
LC_ALL
.
[/EDIT]