Internationalization and localization tools


Locale-Sensitive Windows C++ Functions

int wsprintf(LPTSTR lpOut, LPCTSTR lpFmt, ...);

int wsprintfA(LPSTR lpOut, LPCSTR lpFmt, ...);

int wsprintfW(LPWSTR lpOut, LPCWSTR lpFmt, ...);

Internationalization (I18n) Function Overview

The wsprintf function is a Microsoft Windows version of sprintf. It writes output to lpOut under control of the pszFmt format argument. A null character is placed at the end of the string and the number of characters written is returned, or a value less than the length of the expected output if an error occurs.

wsprintfA is the narrow version of the function; its arguments are single-byte or multibyte strings, and its return is a byte value.

wsprintfW is the wide version of the function; its arguments are wide-character strings, and its return is a wide-character value.

See the MSDN Library for additional information.

I18n Issues

Use the appropriate version of the function as required for internationalization support, ensuring that lpOut is large enough for the chosen platform: it will hold 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.

Note that the Unicode version of wsprintf is not implemented for Windows 95. For that operating system, use the Unicode version of wnsprintfW.

Where locale-dependent numeric formatting is required, use the locale-sensitive GetNumberFormat function to first format numbers and then insert them as strings, rather than using the %d or %i format options, which are locale-independent. See String Formatting in C and C++ for a discussion on locale-sensitive formatting in internationalized applications.

Recommended Replacements*

Due to the security risks of this function, consider using a safe string function.

If wsprintf is called, use the Generic version of the function rather than explicitly calling the narrow or wide versions. wsprintf will be mapped to wsprintfW when the program is compiled with the #define UNICODE switch, and to wsprintfA otherwise. Using the Generic version facilitates switching between an MBCS and UTF-16 Unicode application.

These are shown as the first choices in the following table:

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Locale-Sensitive Windows C++ Functions

 

Lingoport internationalization and localization services and software