INI文件读写
public class INIAccess
{
private string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(
string section, string key, string value, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string section, string key, string def,
StringBuilder retVal, int size, string filePath);
public INIAccess(string iniPath)
{
this.path = iniPath;
}
public void write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.path);
}
public string read(string section, string key, string defaultValue)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, "", temp, 1024, this.path);
return (temp.Length > 0) ? temp.ToString() : defaultValue;
}
}
{
private string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(
string section, string key, string value, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string section, string key, string def,
StringBuilder retVal, int size, string filePath);
public INIAccess(string iniPath)
{
this.path = iniPath;
}
public void write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.path);
}
public string read(string section, string key, string defaultValue)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, "", temp, 1024, this.path);
return (temp.Length > 0) ? temp.ToString() : defaultValue;
}
}