class IniHelp
{
private string iniPath;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public IniHelp(string iniPath)
{
this.iniPath = iniPath;
}
public IniHelp()
{
}
public void setFilePath(string filePath)
{
this.iniPath = filePath;
}
public void iniWrite(string section,string key,string val)
{
WritePrivateProfileString(section,key,val,iniPath);
}
public string iniReadValue(string section,string key)
{
StringBuilder temp=new StringBuilder(500);
int i=GetPrivateProfileString(section,key,"",temp,500,iniPath);
return temp.ToString();
}
public bool existIniFile()
{
return File.Exists(iniPath);
}
}
来源:https://www.cnblogs.com/lao-K/p/11201212.html