1 Star 0 Fork 28

hydeznb/SerialPortForward

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
IniFileHelper.cs 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
老大哥 提交于 2022-07-19 13:59 . 实现串口转发
/// <summary>
/// 类说明:Assistant
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:http://www.sufeinet.com/thread-655-1-1.html
/// </summary>
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace DotNet.Utilities
{
/// <summary>
/// INI文件读写类。
/// </summary>
public class INIFileHelper
{
public string path;
public INIFileHelper(string INIPath)
{
path = INIPath;
}
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
public string IniReadValue(string Section, string Key, object defaultstr)
{
StringBuilder temp = new StringBuilder(2000);
int i = GetPrivateProfileString(Section, Key, "", temp, 2000, this.path);
if (string.IsNullOrEmpty(temp.ToString()))
{
return defaultstr.ToString();
}
return temp.ToString();
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/hydeznb/serial-port-forward.git
git@gitee.com:hydeznb/serial-port-forward.git
hydeznb
serial-port-forward
SerialPortForward
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385