C#读写INI文件
internal class clsIni
{
//文件INI名称
internal string Path;
////声明读写INI文件的API函数
[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);
//传递INI文件名
internal clsIni(string inipath)
{
Path = inipath;
}
//写INI文件
internal void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.Path);
}
//读取INI文件指定
internal string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
return temp.ToString();
}
}
浙公网安备 33010602011771号