几何尺寸与公差论坛

 找回密码
 注册
查看: 1811|回复: 0

如何读取写入ini文件?

[复制链接]
发表于 2007-12-4 14:24:54 | 显示全部楼层 |阅读模式
C#的   
      
           public   class   IniFile   
           {   
                   //文件INI名称   
                   public   string   Path;   
      
                   //声明读写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   IniFile(string   inipath)   
                   {   
                           Path   =   inipath;   
                   }   
      
                   //写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();   
      
                   }   
      
           }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-5-28 17:24 , Processed in 0.032602 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表