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

namespace CoolSoftClient
{
   
//DoIniFile 的摘要说明。
    public class DoIniFile
    {
       
public string path;   //INI文件名

       
public DoIniFile(string INIPath)
        {
            path
= INIPath;
        }

    
//声明读写INI文件的API函数   
        [DllImport("kernel32")]
       
private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
           
        [DllImport(
"kernel32")]
       
private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);

    
//写INI文件      
        public void IniWriteValue(string Section,string Key,string Value)
    {   
      WritePrivateProfileString(Section,Key,Value,
this.path);
    }
 
       
//读取INI文件指定
    public string IniReadValue(string Section,string Key)
    {
      StringBuilder temp
= new StringBuilder(255);
        
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.path);
        
return temp.ToString();
    }
    }
}

调用方法:
DoIniFile IniClass = new DoIniFile(Path);
//声明
IniClass.IniWriteValue("NetSetting","NetWorkAllUrl",textBox1.Text);
//写数据
textBox1.Text = ini.IniReadValue("NetSetting","NetWorkAllUrl");
//读数据

============[转载]============================

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2021-12-16
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-08
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2021-06-05
相关资源
相似解决方案