93.11 C Run Times

The Unicode data type is compatible with the wide-character data type wchar_t in ANSI C, thus allowing access to the wide-character string functions. The C run-time libraries contain wide-character versions of the strxxx string functions. The wide-character version of the functions all start with wcs.

To compile for Unicode or ASCII from the same sources, define a simple set of macros that follow the same naming conventions as the rest of the Windows 32-bit API.

// generic string function macros

#ifdef UNICODE

#define CharStrCmp wcscmp

#define CharStrCpy wcscpy

#define CharStrLen wcslen

#else

#define CharStrCmp strcmp

#define CharStrCpy strcpy

#define CharStrLen strlen

#endif

// explicit string function macros

#define CharStrCmpA strcmp

#define CharStrCpyA strcpy

#define CharStrLenA strlen

#define CharStrCmpW wcscmp

#define CharStrCpyW wcscpy

#define CharStrLenW wcslen

The C run time also provides functions like mbtowc and wctomb, which can be used to translate the C character set to and from Unicode. A more general set of functions that can perform conversion between Unicode and any of a number of Windows character sets and MS-DOS code pages will be part of the Windows 32-bit API.

The printf function supports a %ws format parameter, which corresponds to a wide-character string parameter. Similarly, there is a wcsprintf function, where the format string itself is a Unicode string.