zoukankan      html  css  js  c++  java
  • 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);
          }
         
       }
    }

  • 相关阅读:
    【348】通过 Numpy 创建各式各样的矩阵
    【347】将jupyter notebook嵌入博客园
    【346】TF-IDF
    【345】机器学习入门
    Python 学习入门(28)—— 服务器实例
    HDU 1518 Square
    建立树莓派raspberry交叉编译环境以及编译内核
    Android源码分析-消息队列和Looper
    oracle 表空管理方式(LMT)、ASSM段管理方式、一级位图块、二级位图块、三级位图块。
    Unity手游之路<六>游戏摇杆之Easy Touch 3教程
  • 原文地址:https://www.cnblogs.com/lvfeilong/p/hshgfgfh.html
Copyright © 2011-2022 走看看