using System.Runtime.InteropServices;

         #region [操作ini文件]
        [DllImport("kernel32")]
        private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
        //section:ini文件中的段落;key:ini文件中的关键字;val:ini文件中关键字的数值;filepath:ini文件的完整的路径和名称
        public void IniWrite(string Section, string key, string Value, string FilePath)
        {
            WritePrivateProfileString(Section, key, Value, FilePath);
        }

        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        //section:ini文件中的段落名称;key:ini文件中的关键字;def:无法读取时候时候的缺省数值;retval:读取数值;size:数值的大小;filepath:ini文件的完整路径和名称。
        public string IniRead(string section, string key, string FilePath)
        {
            StringBuilder temp = new StringBuilder(255);
            GetPrivateProfileString(section, key, "", temp, 255, FilePath);
            return temp.ToString();
        }
        #endregion

相关文章:

  • 2021-07-01
  • 2022-02-27
  • 2021-12-11
  • 2021-09-13
猜你喜欢
  • 2021-08-26
  • 2021-06-17
  • 2021-07-06
  • 2021-06-15
  • 2021-06-01
相关资源
相似解决方案