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

84 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
namespace RS.Common
{
public class IniReadWrite
{
#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
#region 读Ini文件
public static string ReadIniData(string Section, string Key, string NoText, string iniFilePath)
{
if (File.Exists(iniFilePath))
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(Section, Key, NoText, temp, 1024, iniFilePath);
return temp.ToString();
}
else
{
return String.Empty;
}
}
#endregion
#region 写Ini文件
public static bool WriteIniData(string Section, string Key, string Value, string iniFilePath)
{
if (File.Exists(iniFilePath))
{
long OpStation = WritePrivateProfileString(Section, Key, Value, iniFilePath);
if (OpStation == 0)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
#endregion
}
public class CommonTag
{
public static string path = System.IO.Directory.GetCurrentDirectory() + "\\Config.ini";
public static string FormStyle = null;
public static string StationIP = null;
public static bool SerialIsOpen = false;
public static string SerialInfoFilePath = "";
}
}