using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace EAS.Distributed { /// /// Ini文件读写类。 /// internal class IniFile { #region API class API { /// /// 写Ini文件。 /// /// /// /// /// /// [DllImport("kernel32")] public static extern long WritePrivateProfileString(string section, string key, string val, string filePath); /// /// 读Ini文件。 /// /// /// /// /// /// /// /// [DllImport("kernel32")] public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); } #endregion private string path = string.Empty; internal IniFile() { } internal IniFile(string path) { this.path = path; } /// /// 路径。 /// internal string FilePath { get { return this.path; } set { this.path = value; } } /// /// 写入Ini指定配置节指定配置键的值。 /// /// 节。 /// 键。 /// 值。 internal void WriteValue(string section, string key, string value) { API.WritePrivateProfileString(section, key, value, this.path); } /// /// 读取Ini指定配置节指定配置键的值 /// /// 节。 /// 键。 /// internal string ReadValue(string section, string key) { StringBuilder dataBuffer = new StringBuilder(1024 * 10); int i = API.GetPrivateProfileString(section, key, string.Empty, dataBuffer, 1024 * 10, this.path); return dataBuffer.ToString(); } } }