You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace POSV.Proxy.Tool
{
public class InIHelper
{
private string Path;
public InIHelper(string path)
{
this.Path = path;
}
/// <summary>
/// 写入INI文件
/// </summary>
/// <param name="section">节点名称[如[TypeName]]</param>
/// <param name="key">键</param>
/// <param name="val">值</param>
/// <param name="filepath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="section">节点名称</param>
/// <param name="key">键</param>
/// <param name="def">值</param>
/// <param name="retval">stringbulider对象</param>
/// <param name="size">字节大小</param>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
/// <summary>
/// 写入
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="iValue"></param>
public void WriteContentValue(string section, string key, string iValue)
{
WritePrivateProfileString(section, key, iValue, this.Path);
}
/// <summary>
/// 读取INI文件中的内容方法
/// </summary>
/// <param name="Section">键</param>
/// <param name="key">值</param>
/// <returns></returns>
public string ReadContentValue(string Section, string key)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(Section, key, "", temp, 1024, this.Path);
return temp.ToString();
}
}
}