# Win32 API

Notes on Win32 API

## ini file

ini file has two type that is classified by character code, ACP (Shift_JIS in Japanese) and Unicode (UTF-16 with LE BOM).
And there are two version Win32 APIs for read/write ini file. ANSI version (GetPrivateProfileStringA, WritePrivateProfileStringA etc) with char * arguments, and wide character version (GetPrivateProfileStringW, WritePrivateProfileStringW etc) with wchar_t * arguments.
Combination of ini file (ACP, Unicode) and API (ANSI version, wide character version) makes 4 patterns.

- ACP ini file : Get/WritePrivateProfileStringA
- ACP ini file : Get/WritePrivateProfileStringW
- Unicode (UTF-16LE) ini file : Get/WritePrivateProfileStringA
- Unicode (UTF-16LE) ini file : Get/WritePrivateProfileStringW

If Windows 2000 or later, conversion is automatically performed inside API, fit to character code of ini file.

- When ANSI API read/write a Unicode ini file, conversion is automatically performed.
- When wide character API read/write a ACP ini file, conversion is automatically performed.
- So possible to use the API transparently regardless of the character encoding of the ini file.
- If Unicode characters that cannot be represented by ACP are written to a non-Unicode ini file, they are replaced by "?" and written to the file.
- If the file has a UTF-16LE BOM (0xff 0xfe) at the beginning, the ini file is regarded as Unicode file.
  - When a file is not exist. When It is created with the WritePrivateProfileStringA/W, it will be written in ACP.
  - When a file is already exist that only included BOM (0xff 0xfe), write by WritePrivateProfileStringA/W, it will be written in Unicode.

If Windows NT 4, "ANSI API and ACP ini file" and "wide character API and ACP ini file" combination will works fine.
When Wide character API read/write a ACP ini file, conversion is automatically performed.

If Windows 95, 98, Me, only "ANSI API and ACP ini file" combination will works fine.
Automatically conversion does not seem to be work.

| Windows 2000- | Windows NT 4 | Windows 95, 98, Me
--- | --- | --- | ---
| ANSI API | Wide API | ANSI API | Wide API | ANSI API | Wide API
ACP ini file | OK | OK | OK | OK | OK | NG
Unicode (UTF-16LE) ini file | OK | OK | NG | NG | NG | NG