
MyToolkit函式庫加入Ini檔案讀寫功能
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5: 6: using System.Runtime.InteropServices;
7: namespace MyToolkit
8: { 9: 10: public class IniFileTool
11: {12: public string path;
13: [DllImport("kernel32")]
14: private static extern long WritePrivateProfileString(string section,
15: string key, string val, string filePath);
16: [DllImport("kernel32")]
17: private static extern int GetPrivateProfileString(string section,
18: string key, string def, StringBuilder retVal,
19: int size, string filePath);
20: /// <summary>
21: /// INIFile Constructor.
22: /// </summary>
23: /// <PARAM name="INIPath"></PARAM>
24: public IniFileTool(string INIPath)
25: { 26: path = INIPath; 27: }28: /// <summary>
29: /// Write Data to the INI File
30: /// </summary>
31: /// <PARAM name="Section"></PARAM>
32: /// Section name
33: /// <PARAM name="Key"></PARAM>
34: /// Key Name
35: /// <PARAM name="Value"></PARAM>
36: /// Value Name
37: public void IniWriteValue(string Section, string Key, string Value)
38: {39: WritePrivateProfileString(Section, Key, Value, this.path);
40: } 41: 42: /// <summary>
43: /// Read Data Value From the Ini File
44: /// </summary>
45: /// <PARAM name="Section"></PARAM>
46: /// <PARAM name="Key"></PARAM>
47: /// <PARAM name="Path"></PARAM>
48: /// <returns></returns>
49: public string IniReadValue(string Section, string Key)
50: {51: StringBuilder temp = new StringBuilder(255);
52: int i = GetPrivateProfileString(Section, Key, "", temp,
53: 255, this.path);
54: return temp.ToString();
55: 56: } 57: } 58: }








