Most string operations for Unicode can be coded using the same logic used for handling the Windows ANSI character set, except that the basic unit of operation is a 16-bit quantity instead of an 8-bit byte. The header files provide a number of type definitions that make it easy to create sources that can be compiled for Unicode or the ANSI character set.
The following example shows the method used in the Win32 header files to define three sets of types: a set of generic type definitions, which depend on the state of the UNICODE variable, and two sets of explicit type definitions. The first set of explicit type definitions provides a set of type definitions for use with the existing Windows (ANSI) character set, and the last is a set of type definitions for Unicode (or wide) characters.
/* Generic Types */
#ifdef UNICODE
typedef wchar_t TCHAR;
#else
typedef unsigned char TCHAR;
#endif
typedef TCHAR * LPTSTR, *LPTCH;
/* 8-bit character specific */
typedef unsigned char CHAR;
typedef CHAR *LPSTR, *LPCH;
/* Unicode specific (wide characters) */
typedef unsigned wchar_t WCHAR;
typedef WCHAR *LPWSTR, *LPWCH;
A rare example of a function that takes parameters using the explicit types is MultiByteToWideChar, which performs translation between ANSI (and other 8-bit character sets) and Unicode. Here the source parameter is LPSTR and the destination parameter is LPWSTR.
Applications are encouraged to use the generic data types, but the specific types exist for applications that require mixed type control.