Console Application Issues

The 8-bit console functions use the OEM code page. All other functions use the ANSI code page by default. This means that strings returned by the console functions may not be processed correctly by the other functions and vice versa. For example, if FindFirstFileA returns a string that contains certain extended ANSI characters, WriteConsoleA will not display the string properly.

The best long-term solution for a console application is to use Unicode. Barring that solution, a console application should use the SetFileApisToOEM function. That function changes relevant file functions so that they produce OEM character set strings rather than ANSI character set strings.

The following are file functions:

CopyFile GetFileAttributes LoadLibrary
CreateDirectory GetFullPathName LoadLibraryEx
CreateFile GetModuleFileName MoveFile
CreateProcess GetModuleHandle MoveFileEx
DeleteFile GetSystemDirectory OpenFile
FindFirstFile GetTempFileName RemoveDirectory
FindNextFile GetTempPath SearchPath
GetCurrentDirectory GetVolumeInformation SetCurrentDirectory
GetDiskFreeSpace GetWindowsDirectory SetFileAttributes

When dealing with command lines, a console application should obtain the command line in Unicode form and convert it to OEM form, using the relevant character-to-OEM functions. Note, also, that argv uses the ANSI character set.