using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace HelloCSharp
{
    //[section]
    //key=value
    //
    class IniHelper
    {
        /// <summary>
        /// ini文件的路径
        /// </summary>
        private string filePath;


        [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 filePath)
        {
            this.filePath = filePath;
        }

        public void IniWriteValue(string section, string key, string val)
        {
            WritePrivateProfileString(section, key, val, filePath);
        }

        public string IniReadValue(string section, string key)
        {
            StringBuilder temp = new StringBuilder(500);
            GetPrivateProfileString(section, key, "", temp, 500, filePath);
            return temp.ToString();
        }
    }
}

 

相关文章:

  • 2021-08-19
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-10-28
  • 2021-08-21
  • 2022-01-11
相关资源
相似解决方案