Internationalization and localization tools


Windows Safe String Function

HRESULT StringCbCopyN(LPTSTR pszDest, size_t cbDest, LPCTSTR pszSrc, size_t cbSrc);

HRESULT StringCbCopyNA(LPSTR pszDest, size_t cbDest, LPCSTR pszSrc, size_t cbSrc);

HRESULT StringCbCopyNW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszSrc, size_t cbSrc);

HRESULT StringCbCopyNEx(LPTSTR pszDest, size_t cbDest, LPCTSTR pszSrc, size_t cbSrc, LPTSTR *ppszDestEnd, size_t *pcbRemaining, DWORD dwFlags);

HRESULT StringCbCopyNExA(LPSTR pszDest, size_t cbDest, LPCSTR pszSrc, size_t cbSrc, LPSTR *ppszDestEnd, size_t *pcbRemaining, DWORD dwFlags);

HRESULT StringCbCopyNExW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszSrc, size_t cbSrc, LPWSTR *ppszDestEnd, size_t *pcbRemaining, DWORD dwFlags);

Internationalization (I18n) Function Overview

The StringCbCopyN function is a replacement for locale-sensitive string copy functions. It copies no more than cbSrc bytes of pszStr to the end of pszDest, using the byte size of the buffer stored in cbDest to ensure that the destination string buffer is not overrun. In the event of an error, a negative HRESULT value is returned, indicating the error.

StringCbCopyNEx adds advanced functionality: It returns a pointer to the end of the destination string as well as the number of bytes left unused in that string, and uses dwFlags for additional control.

The narrow versions of these functions, StringCbCopyNA and StringCbCopyNExA, pass in single-byte or multibyte strings and lengths that refer to the number of bytes.

The wide versions of these functions, StringCbCopyNW and StringCbCopyNExW, pass in wide-character strings, but, like the narrow versions, lengths that refer to the number of bytes.

I18n Issues

Use the appropriate version of the function as required for internationalization support, and ensure that cbDest is set to the byte size of the destination string buffer. 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. 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.

Windows Safe String Functions

 

Lingoport internationalization and localization services and software