SaleWPF/Service/IniFileHelper.cs

(开头部分) 11KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SaleWPF.Service
{
    public class IniFileHelper
    {

        private string filePath;//ini文件名
        private static readonly object thisLock = new object();
        public IniFileHelper(string _filePath)
        {
            this.filePath = _filePath;
            CreateInIFile();
        }

        //声明调用错误信息
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetLastError();



        [DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]
        private static extern uint GetPrivateProfileStringA(string section, string key, string def, Byte[] retVal, int size, string filePath);


        [DllImport("kernel32", SetLastError = true)]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        [DllImport("kernel32", SetLastError = true)]
        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="value"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool INIWriteValue(string section, string key, string value, out string errorMsg)
        {
            lock (thisLock)
            {
                bool result = false;
                errorMsg = string.Empty;
                try
                {
                    if (key == null)
                    {
                        errorMsg = $"key不能为Null,否则会删除section:{section}整个节点";
                    }
后面还有 281 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。