Most .NET applications do not need access to the old INI file format, so Microsoft decided not to include it in the .NET framework. Multiple other options are available, from .config files to the Registry. However, there are a handful of situations where an old INI file must be read.
I wrote this class while doing some test development on an ini2reg-style program (a program that would read an existing INI file and then write appropriate Registry entries so that the information is read out of the registry instead; see MSDN: GetPrivateProfileString, MSDN: INF Ini2Reg, and MSDN: NT Resource Kit, Chapter 26).
Note that this is not a particularly well-designed class; I wrote it quickly. It’s posted here as an example of moderately difficult interop; specifically, how to read a multi-string value, where “multi-string” means a single buffer that is double-null-terminated and may contain embedded (single) nulls.
About Stephen Cleary
Stephen Cleary is a Christian, husband, father, and programmer living in Northern Michigan.