1
讯享网using System;
2
using System.Runtime.InteropServices;
3
using System.Text;
4
5
namespace IPVOD.Hotel.Remoting
6

{
7
///// <summary>
8
/// INI文件的操作类
9
/// </summary>
10
public class IniFile
11
{
12
public string Path;
13
14
public IniFile(string path)
15
{
16
this.Path = path;
17
}
18
19
声明读写INI文件的API函数#region 声明读写INI文件的API函数
20
[DllImport(“kernel32”)]
21
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
22
23
[DllImport(“kernel32”)]
24
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);
25
26
[DllImport(“kernel32”)]
27
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
28
#endregion
29
30
///// <summary>
31
/// 写INI文件
32
/// </summary>
33
/// <param name=“section”>段落</param>
34
/// <param name=“key”>键</param>
35
/// <param name=“iValue”>值</param>
36
public void IniWriteValue(string section, string key, string iValue)
37
{
38
WritePrivateProfileString(section, key, iValue, this.Path);
39
}
40
41
///// <summary>
42
/// 读取INI文件
43
/// </summary>
44
/// <param name=“section”>段落</param>
45
/// <param name=“key”>键</param>
46
/// <returns>返回的键值</returns>
47
public string IniReadValue(string section, string key)
48
{
49
StringBuilder temp = new StringBuilder(255);
50
51
int i = GetPrivateProfileString(section, key, ””, temp, 255, this.Path);
52
return temp.ToString();
53
}
54
55
///// <summary>
56
/// 读取INI文件
57
/// </summary>
58
/// <param name=“Section”>段,格式[]</param>
59
/// <param name=“Key”>键</param>
60
/// <returns>返回byte类型的section组或键值组</returns>
61
public byte[] IniReadValues(string section, string key)
62
{
63
byte[] temp = new byte[255];
64
65
int i = GetPrivateProfileString(section, key, ””, temp, 255, this.Path);
66
return temp;
67
}
68
}
69
}
70


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/192910.html