• C# INI文件操作类(IniFileAPI)


    C# Code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Runtime.InteropServices;

    namespace CSFramework.Tech2011
    {
       public class IniFileAPI
       {
          private string fileName;
          [DllImport("kernel32")]
          private static extern int GetPrivateProfileInt(
          string lpAppName,// 指向包含 Section 名称的字符串地址
          string lpKeyName,// 指向包含 Key 名称的字符串地址
          int nDefault,// 如果 Key 值没有找到,则返回缺省的值是多少
          string lpFileName
          );
          [DllImport("kernel32")]
          private static extern int GetPrivateProfileString(
          string lpAppName,// 指向包含 Section 名称的字符串地址
          string lpKeyName,// 指向包含 Key 名称的字符串地址
          string lpDefault,// 如果 Key 值没有找到,则返回缺省的字符串的地址
          StringBuilder lpReturnedString,// 返回字符串的缓冲区地址
          int nSize,// 缓冲区的长度
          string lpFileName
          );
          [DllImport("kernel32")]
          private static extern bool WritePrivateProfileString(
          string lpAppName,// 指向包含 Section 名称的字符串地址
          string lpKeyName,// 指向包含 Key 名称的字符串地址
          string lpString,// 要写的字符串地址
          string lpFileName
          );
         
          public void IniFile(string filename)
          {
             fileName = filename;
          }
          public int GetInt(string section, string key, int def)
          {
             return GetPrivateProfileInt(section, key, def, fileName);
          }
          public string GetString(string section, string key, string def)
          {
             StringBuilder temp = new StringBuilder(1024);
             GetPrivateProfileString(section, key, def, temp, 1024, fileName);
             return temp.ToString();
          }
          public void WriteInt(string section, string key, int iVal)
          {
             WritePrivateProfileString(section, key, iVal.ToString(), fileName);
          }
          public void WriteString(string section, string key, string strVal)
          {
             WritePrivateProfileString(section, key, strVal, fileName);
          }
          public void DelKey(string section, string key)
          {
             WritePrivateProfileString(section, key, null, fileName);
          }
          public void DelSection(string section)
          {
             WritePrivateProfileString(section, null, null, fileName);
          }
         
       }
    }

  • 相关阅读:
    前后端交互, 安装drf, restful接口规范, pycharm断点调试
    django中文设置, axios, CORS, 全局js配置, Vue配置jq + bs
    js原型, Vue项目环境搭建, Vue项目目录结构, Vue项目生命周期, 小组件使用, 全局样式, 路由跳转, 组件的生命周期钩子, 路由传参
    Vue组件
    Vue表单指令, 条件指令, 循环指令, 成员
    question1 赋值运算操作符
    CH15 面向对象程序设计
    CH12 动态内存
    CH11 关联容器
    CH10 泛型算法
  • 原文地址:https://www.cnblogs.com/lvfeilong/p/hshgfgfh.html
Copyright © 2020-2023  润新知