-
Notifications
You must be signed in to change notification settings - Fork 8
/
Config.cs
41 lines (33 loc) · 1.23 KB
/
Config.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace pringApp
{
class Config
{
string filePath = Application.StartupPath + "\\Config.ini";
#region API函数声明
[DllImport("kernel32")]//返回0表示失败,非0为成功
private static extern long WritePrivateProfileString(string section, string key,
string val, string filePath);
[DllImport("kernel32")]//返回取得字符串缓冲区的长度
private static extern long GetPrivateProfileString(string section, string key,
string def, StringBuilder retVal, int size, string filePath);
#endregion
public Config() { }
public string ReadString(string section, string name, string def)
{
StringBuilder vRetSb = new StringBuilder(2048);
GetPrivateProfileString(section, name, def, vRetSb, 2048, filePath);
return vRetSb.ToString();
}
public void WriteString(string section, string name, string strVal)
{
WritePrivateProfileString(section, name, strVal, filePath);
}
}
}