Do Not Assume That Characters Are Always 8-Bit

Code that assumes that characters are 8 bits wide does not work for double-byte character sets or Unicode.

szString = szString + 2; // Skip two characters.

Because characters in double-byte character sets might be 1 or 2 bytes wide, it is safer to use the system call CharNext, which correctly returns a pointer to the next character in any context.

szString = CharNext(CharNext(szString));

The following code will allocate a buffer that is only half the size necessary for a Unicode string:

int cch = lstrlen(szString);
char *pszBuffer = malloc(cch);

As described in detail in Chapter 3, you can use generic declarations and compile your code for Unicode, single-byte character sets, or double-byte character sets. The code below will allocate a buffer that is the correct size in any of these cases:

int cch = lstrlen(szString);
TCHAR *pszBuffer = malloc(cch*sizeof(TCHAR));