1 public partial class ReadIniFile
2 {
3 public static ReadIniFile ri;
4 private ReadIniFile() { }
5
6 public static ReadIniFile GetInstance()
7 {
8 ri = new ReadIniFile();
9 //if (ri == null)
10 //{
11 // ri = new ReadIniFile();
12 //}
13 return ri;
14 }
15
16
17 static string iniPath = System.AppDomain.CurrentDomain.BaseDirectory + @"SetConfig.ini";
18
19 public static string IniReadValue(string Section, string Key)
20 {
21 StringBuilder temp = new StringBuilder(500);
22 //string iniPath = System.AppDomain.CurrentDomain.BaseDirectory + @"SetRate.ini";
23 int i = GetPrivateProfileString(Section, Key, "", temp, 500, iniPath);
24 return temp.ToString();
25 }
26
27 public void WriteINIValue(string section, string key, string val)
28 {
29 WritePrivateProfileString(section, key, val, iniPath);
30 }
31
32
33 [DllImport("kernel32")]
34 private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
35
36 [DllImport("kernel32")]
37 private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
38
39
40 }
1.需引入命名空間
using System.Runtime.InteropServices;