国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

C#上位機(jī)對配置文件的操作演示

2023-07-22 09:29 作者:donet工控少俠  | 我要投稿

??public class IniConfigHelper

??{

????public static string filePath = "";


????#region API函數(shù)聲明


????[DllImport("kernel32")]

????private static extern long WritePrivateProfileString(string section, string key,

??????string val, string filePath);


????//需要調(diào)用GetPrivateProfileString的重載

????[DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]

????private static extern long GetPrivateProfileString(string section, string key,

??????string def, StringBuilder retVal, int size, string filePath);


????[DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]

????private static extern uint GetPrivateProfileStringA(string section, string key,

??????string def, Byte[] retVal, int size, string filePath);


????#endregion


????#region 獲取所有的Sections

????/// <summary>

????/// 獲取所有的Sections

????/// </summary>

????/// <param name="iniFilename">文件路徑</param>

????/// <returns>Sections集合</returns>

????public static List<string> ReadSections(string iniFilename)

????{

??????List<string> result = new List<string>();

??????Byte[] buf = new Byte[65536];

??????uint len = GetPrivateProfileStringA(null, null, null, buf, buf.Length, iniFilename);

??????int j = 0;

??????for (int i = 0; i < len; i++)

????????if (buf[i] == 0)

????????{

??????????result.Add(Encoding.Default.GetString(buf, j, i - j));

??????????j = i + 1;

????????}

??????return result;

????}


????#endregion


????#region 獲取指定Section下的所有Keys

????/// <summary>

????/// 獲取指定Section下的所有Keys

????/// </summary>

????/// <param name="SectionName">SectionName</param>

????/// <param name="iniFilename">文件路徑</param>

????/// <returns>Keys集合</returns>

????public static List<string> ReadKeys(string SectionName, string iniFilename)

????{

??????List<string> result = new List<string>();

??????Byte[] buf = new Byte[65536];

??????uint len = GetPrivateProfileStringA(SectionName, null, null, buf, buf.Length, iniFilename);

??????int j = 0;

??????for (int i = 0; i < len; i++)

????????if (buf[i] == 0)

????????{

??????????result.Add(Encoding.Default.GetString(buf, j, i - j));

??????????j = i + 1;

????????}

??????return result;

????}


????#endregion


????#region 讀Ini文件


????public static string ReadIniData(string Section, string Key, string NoText)

????{

??????return ReadIniData(Section, Key, NoText, filePath);

????}

????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)

????{

??????return WriteIniData(Section, Key, Value, filePath);

????}


????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

??}

C#上位機(jī)對配置文件的操作演示的評論 (共 條)

分享到微博請遵守國家法律
连州市| 临汾市| 平果县| 西青区| 卢龙县| 铜川市| 丹寨县| 南丹县| 泰和县| 土默特左旗| 兴山县| 鞍山市| 台北市| 临武县| 乌拉特中旗| 延长县| 南乐县| 漾濞| 平阴县| 白山市| 屯门区| 曲阜市| 石阡县| 武义县| 麟游县| 绥棱县| 咸阳市| 洛浦县| 肇源县| 紫金县| 资源县| 靖州| 泾川县| 吕梁市| 汝阳县| 巴青县| 南涧| 开鲁县| 上饶市| 全州县| 彭泽县|