所谓的潇洒

导航

IniHelper

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();
        }
    }
}

 

posted on 2020-11-11 16:36  所谓的潇洒  阅读(147)  评论(0编辑  收藏  举报