C# WinAPI: How to Handle INI files
How to handle windows INI files via .NET Framework ? The INI file format is a standard for configuration files in windows. Using of registry or XML files to store configuration settings is more popular today. However many windows applications and features use INI files format. Internet Explorer favorites is one example.
In order to create some API to handle INI files from managed code we need to use a couple of interop methods defined in kernel32: WritePrivateProfileString to write and GetPrivateProfileString to read from INI file:
[DllImport("kernel32.dll")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32.dll")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
Enjoy :)
Saturday, April 19, 2008 2:28 AM