using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace MyProject
{
public class IniHelper
{
private string iniPath = string.Empty;
[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 IniHelper(string iniPath)
{
this.iniPath = iniPath;
}
/// <summary>
/// 写
/// </summary>
/// <param name="section">段落标题</param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string section, string Key, string Value)
{
WritePrivateProfileString(section, Key, Value, this.iniPath);
}
/// <summary>
/// 读
/// </summary>
/// <param name="section">段落标题</param>
/// <param name="Key"></param>
/// <returns></returns>
public string IniReadValue(string section, string Key)
{
StringBuilder temp = new StringBuilder(500);
int i = GetPrivateProfileString(section, Key, "", temp, 500, this.iniPath);
return temp.ToString();
}
}
}