代码:
public class IniManger
{
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public static void Write(string section, string key, string value, string sPath)
{
WritePrivateProfileString(section, key, value, sPath);
}
public static string ReadValue(string section, string key, string sPath)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section, key, "", temp, 1024, sPath);
return temp.ToString();
}
}
本质是调用WinBase.h中的方法。