Ejemplo n.º 1
0
 /// <summary>
 /// 删除指定section
 /// </summary>
 public bool DeleteIniSection(string section)
 {
     try
     {
         if (section.Trim().Length <= 0)
         {
             flag = false;
         }
         else
         {
             if (!APIsWin32.WritePrivateProfileString(section, null, null, this._Path))
             {
                 flag = false;
             }
             else
             {
                 flag = true;
             }
         }
     }
     catch
     {
         flag = false;
     }
     return(flag);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取指定节点下的所有key 和value
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        public ArrayList GetIniSectionValue(string section)
        {
            ArrayList li = new ArrayList();

            byte[] buffer = new byte[32768];
            int    bufLen = 0;

            bufLen = APIsWin32.GetPrivateProfileSection(section, buffer, buffer.GetUpperBound(0), this._Path);
            if (bufLen > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < bufLen; i++)
                {
                    if (buffer[i] != 0)
                    {
                        sb.Append((char)buffer[i]);
                    }
                    else
                    {
                        if (sb.Length > 0)
                        {
                            li.Add(sb.ToString());
                            sb = new StringBuilder();
                        }
                    }
                }
            }
            return(li);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 修改指定section的key的值
 /// </summary>
 public bool EditIniKey(string section, string key, string value)
 {
     try
     {
         if (section.Trim().Length <= 0 || key.Trim().Length <= 0 || value.Trim().Length <= 0)
         {
             flag = false;
         }
         else
         {
             if (!APIsWin32.WritePrivateProfileString(section, key, value, this._Path))
             {
                 flag = false;
             }
             else
             {
                 flag = true;
             }
         }
     }
     catch
     {
         flag = false;
     }
     return(flag);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取指定节点的所有Key的名称
        /// </summary>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public ArrayList ReadKeys(string sectionName)
        {
            byte[] buffer = new byte[5120];
            int    rel    = APIsWin32.GetPrivateProfileStringA(sectionName, null, "", buffer, buffer.GetUpperBound(0), this._Path);

            int       iCnt, iPos;
            ArrayList arrayList = new ArrayList();
            string    tmp;

            if (rel > 0)
            {
                iCnt = 0; iPos = 0;
                for (iCnt = 0; iCnt < rel; iCnt++)
                {
                    if (buffer[iCnt] == 0x00)
                    {
                        tmp  = System.Text.ASCIIEncoding.Default.GetString(buffer, iPos, iCnt - iPos).Trim();
                        iPos = iCnt + 1;
                        if (tmp != "")
                        {
                            arrayList.Add(tmp);
                        }
                    }
                }
            }
            return(arrayList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 读取Count
        /// </summary>
        public int GetCount(string section, string key)
        {
            StringBuilder builder = new StringBuilder(255);

            APIsWin32.GetPrivateProfileString(section, key, "", builder, 255, _Path);
            return(Convert.ToInt16(builder.ToString()));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Read *.ini
        /// </summary>
        /// <param name="section">Node</param>
        /// <param name="key">字段</param>
        /// <returns>属性值</returns>
        public string ReadValue(string section, string key)
        {
            StringBuilder builder = new StringBuilder(1024);

            APIsWin32.GetPrivateProfileString(section, key, "", builder, 1024, _Path);
            return(builder.ToString());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 从指定的节点中获取一个整数值( Long,
 /// 找到的key的值;如指定的key未找到,就返回默认值。
 /// 如找到的数字不是一个合法的整数,函数会返回其中合法的一部分。如,对于“xyz=55zz”这个条目,函数返回55。)
 /// </summary>
 public int GetIniKeyValueForInt(string section, string key)
 {
     if (section.Trim().Length <= 0 || key.Trim().Length <= 0)
     {
         return(0);
     }
     return(APIsWin32.GetPrivateProfileInt(section, key, 0, this._Path));
 }
Ejemplo n.º 8
0
        //将要执行的函数转换为委托
        public Delegate Invoke(string APIName, Type t)
        {
            IntPtr api = APIsWin32.GetProcAddress(hLib, APIName);

            return((Delegate)Marshal.GetDelegateForFunctionPointer(api, t));
        }
Ejemplo n.º 9
0
 public DllInvoke(string DLLPath)
 {
     hLib = APIsWin32.LoadLibrary(DLLPath);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Write *.ini
 /// </summary>
 /// <param name="section">Node</param>
 /// <param name="key">字段</param>
 /// <param name="value">属性值</param>
 public void WriteValue(string section, string key, string value)
 {
     APIsWin32.WritePrivateProfileString(section, key, value, _Path);
 }