最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ī)對配置文件的操作演示的評論 (共 條)

分享到微博請遵守國家法律
错那县| 邵阳市| 淮南市| 凤庆县| 建湖县| 临清市| 灵川县| 康乐县| 顺平县| 敦煌市| 平乡县| 平凉市| 土默特右旗| 伊吾县| 崇左市| 沐川县| 绥阳县| 麻江县| 云阳县| 宾阳县| 宁远县| 枣阳市| 西华县| 大田县| 灌南县| 孝义市| 东兴市| 洪湖市| 高密市| 宿迁市| 双辽市| 双峰县| 凤阳县| 平谷区| 邵武市| 多伦县| 延长县| 西盟| 雷山县| 罗城| 南汇区|