Your cast in CharLower is raising that error. Before doing that, you need to set the high order byte of the pointer passed to CharLower equals to ZERO.
From MSDN reference on the function:
If the operand is a character string,
the function returns a pointer to the
converted string. Because the string
is converted in place, the return
value is equal to lpsz.
If the operand is a single character,
the return value is a 32-bit value
whose high-order word is zero, and
low-order word contains the converted
character.
Something like this might work:
#define ltolower(ch) CharLower(0x00ff & ch)
If you are using a C++ compiler, you might also need a CAST operator:
#define ltolower(ch) CharLower((LPTSTR)(0x00ff & ch))
Haven't tested it though...