Search code examples
registryini

What are the differences in functionality when INI files are mapped to the Registry?


I have an application using INI files and the behavior does not seem to be identical when I map my INI files into the Registry as described at WritePrivateProfileString [MSDN], although the documentation says

the change in the storage location has no effect on the function's behavior.

What are the differences between an INI file on disk and an INI file mapped into Registry?


Solution

  • There are several differences:

    • The Registry is Unicode, while most INI files are probably ANSI (as long as they don't have a UTF16-LE header).
    • GetPrivateProfileString() overflows at 65536 bytes. This means that you can read 65535 characters from an ANSI file, but only 32767 characters from the Registry.
    • A Registry value can contain newlines, while a new line in an INI file starts a new key (basically terminating the value).
    • Leading and trailing whitespace (spaces, tabs and vertical tabs) are ignored when reading a value from an INI file but will be returned when reading from Registry.
    • Writing a key which starts with a semicolon will turn it into a comment when using a file. In the Registry it will be treated like a real key.

    Note that this list may be incomplete and change with new implementations from Microsoft. These tests were made on Windows 10 21H1.

    All this should be enough to convince people to switch from INI files to other configuration file formats. This API is a relict from 16 Bit Windows and should not be used any more. Your config files needn't be XML, maybe JSON or YAML is good enough.