Locale-Sensitive Windows C++ Function
int GetDateFormat(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpDate, LPCTSTR lpFormat, LPTSTR lpDateStr, int cchDate);
int GetDateFormatA(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpDate, LPCSTR lpFormat, LPSTR lpDateStr, int cchDate);
int GetDateFormatW(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpDate, LPCWSTR lpFormat, LPWSTR lpDateStr, int cchDate);
Internationalization (I18n) Function Overview
The GetDateFormat function formats the date variable lpDate ,
based on the locale specified by Locale and options specified
by dwFlags and lpFormat , and stores the resulting date string in lpDateStr .
If successful, it returns the number of TCHARs , including the null-terminating character,
written to lpDateStr . In the event of an error, GetDateFormat returns 0 and
sets extended error information that can be obtained by calling GetLastError .
cchDate should be set to either the size, in TCHARs , of the
lpDateStr 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
lpDateStr is not used.
GetDateFormatA is the narrow version of the function, where lpFormat and lpDateStr
are single or multibyte strings and cchDate and the return are byte length values.
GetDateFormatW is the wide version of the function, where lpFormat and lpDateStr
are wide-character strings and cchDate and the return are wide-character (WCHAR ) length values.
See the MSDN Library for
additional information on the dwFlags and lpFormat settings.
I18n Issues
Use the appropriate version of the function as required for internationalization support, noting the following:
Formulate the correct locale to pass into GetDateFormat .
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 cchDate 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.
|