public class IniFile
{
//ini文件的路径
[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 IniFile() // ctor function
{
}
//写ini文件
public void IniWriteValue(string Section, string Key, string Value, string inipath)
{
WritePrivateProfileString(Section, Key, Value, inipath);
}
//读ini文件
public string IniReadValue(string Section, string Key, string inipath)
{
int buffer;
buffer = 255;//定义长度
StringBuilder temp = new StringBuilder(buffer);
GetPrivateProfileString(Section, Key, "", temp, buffer, inipath);
return temp.ToString();
}
}
{
//ini文件的路径
[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 IniFile() // ctor function
{
}
//写ini文件
public void IniWriteValue(string Section, string Key, string Value, string inipath)
{
WritePrivateProfileString(Section, Key, Value, inipath);
}
//读ini文件
public string IniReadValue(string Section, string Key, string inipath)
{
int buffer;
buffer = 255;//定义长度
StringBuilder temp = new StringBuilder(buffer);
GetPrivateProfileString(Section, Key, "", temp, buffer, inipath);
return temp.ToString();
}
}