Fork me on GitHub
C#读写ini文件
using System.Text;
using System.Runtime.InteropServices;

[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 void IniWriteValue(string Section, string Key, string Value, string filepath)
    {
        WritePrivateProfileString(Section, Key, Value, filepath);
    }

    public string IniReadValue(string Section, string Key, string filepath)
    {
        StringBuilder temp = new StringBuilder(255);
        int i = GetPrivateProfileString(Section, Key, "", temp,
        255, filepath);
        return temp.ToString();
    }

posted on 2010-04-26 23:23  HackerVirus  阅读(216)  评论(0)    收藏  举报