Locale-Sensitive Windows C++ Function
int GetNumberFormat(LCID Locale, DWORD dwFlags, LPCTSTR lpValue, CONST NUMBERFMT *lpFormat, LPTSTR lpNumberStr, int cchNumber);
int GetNumberFormatA(LCID Locale, DWORD dwFlags, LPTSTR lpValue, CONST NUMBERFMT *lpFormat, LPSTR lpNumberStr, int cchNumber);
int GetNumberFormatW(LCID Locale, DWORD dwFlags, LPWTSTR lpValue, CONST NUMBERFMT *lpFormat, LPWSTR lpNumberStr, int cchNumber);
Internationalization (I18n) Function Overview
The GetNumberFormat function formats the number string lpValue
into a number string customized for the
locale specified by Locale and the options specified
by dwFlags and lpFormat , and stores the resulting string in lpNumberStr .
If successful, it returns the number of TCHARs , including the null-terminating character,
written to lpNumberStr . In the event of an error, GetNumberFormat returns 0 and
sets extended error information that can be obtained by calling GetLastError .
cchNumber should be set to either the size, in TCHARs , of the
lpNumberStr buffer, or to 0 , in which case, the function returns
the number of TCHARs required to hold the information, and the buffer pointed to by
lpNumberStr is not used.
GetNumberFormatA is the narrow version of the function, where lpValue and lpNumberStr
are single or multibyte strings and cchNumber and the return are byte length values.
GetNumberFormatW is the wide version of the function, where lpValue and lpNumberStr
are wide-character strings and cchNumber and the return are wide-character (WCHAR ) length values.
See the MSDN Library for
additional information.
I18n Issues
Use the appropriate version of the function as required for internationalization support, noting the following:
Formulate the correct LCID to pass into GetNumberFormat .
Although there are two predefined LCID constants that may be used:
LOCALE_SYSTEM_DEFAULT
(the system's default locale returned by GetSystemDefaultLCID )
and LOCALE_USER_DEFAULT (the current user's default locale returned by
GetUserDefaultLCID ),
neither of these will work in an internationalized application where the locale is independent of
the user's system settings.
Ensure that if cchNumber is non-zero, it is set correctly for the chosen platform; bytes for the narrow version and WCHARs for the wide version. See Locale-Sensitive Length Functions
for a discussion on multibyte and wide character sizes.
Recommended Replacements*
When possible, use the Generic version of the function, rather than the narrow or wide versions, and let the Windows #define UNICODE switch determine which version of the function will be called.
*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.
|