コード例 #1
0
 /**/
 /// <summary>
 /// 读取INI文件
 /// </summary>
 /// <param name="Section">段,格式[]</param>
 /// <param name="Key">键</param>
 /// <returns>返回byte类型的section组或键值组</returns>
 public byte[] IniReadValues(string section, string key)
 {
     byte[] temp = new byte[255];
     try
     {
         int i = GetPrivateProfileString(section, key, "", temp, 255, this.Path);
     }
     catch (Exception ex)
     {
         LogManager.WriteFileLog("", Class, "byte[] IniReadValues(string section, string key)", ex);
     }
     return(temp);
 }
コード例 #2
0
        /**/
        /// <summary>
        /// 写INI文件
        /// </summary>
        /// <param name="section">段落</param>
        /// <param name="key">键</param>
        /// <param name="iValue">值</param>
        public void IniWriteValue(string section, string key, string iValue)
        {
            try
            {
                WritePrivateProfileString(section, key, iValue, this.Path);
            }
            catch (Exception ex)
            {
                LogManager.WriteFileLog("", Class, "InterfaceAttribute", ex);
            }
        }

        /**/
        /// <summary>
        /// 读取INI文件
        /// </summary>
        /// <param name="section">段落</param>
        /// <param name="key">键</param>
        /// <returns>返回的键值</returns>
        public string IniReadValue(string section, string key)
        {
            string readValue = string.Empty;

            try
            {
                byte[] byteAr     = new byte[1024];
                uint   resultSize = GetPrivateProfileStringByByteArray(section, key, "", byteAr, (uint)byteAr.Length, this.Path);
                readValue = Encoding.Unicode.GetString(byteAr, 0, (int)resultSize * 2);

                // Old solution
                //int i = GetPrivateProfileString(section, key, "", temp, 255, this.Path);
            }
            catch (Exception ex)
            {
                LogManager.WriteFileLog("", Class, "string IniReadValue(string section, string key)", ex);
            }
            return(readValue);
        }