Remove cast from malloc.
Correct TCHAR type name. Convert ASCII functions to TCHAR.