版权声明:本文为博主原创文章,不需博主允许即可随意转载。 https://blog.csdn.net/a_dev/article/details/85006721
代码:
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中的方法。