Platform SDK: Files and I/O

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 the file functions:

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

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.