现在的位置: 首页 > 综合 > 正文

读写INI

2013年01月13日 ⁄ 综合 ⁄ 共 757字 ⁄ 字号 评论关闭

 //读写INI

public class GF_INI
    {
        [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);
        [DllImport("kernel32.dll")]
        public static extern int Beep(int dwFreq, int dwDuration);

        //读ini
        public static void iniFile_SetVal(string in_filename, string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, in_filename);
        }

        //写INI
        public static string iniFile_GetVal(string in_filename, string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp, 255, in_filename);
            if (i == 0)
                return "";
            else
                return temp.ToString();
        }
    }

 

抱歉!评论已关闭.