c#中調用操作INI文件的API

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

//要調用WINDOWS API函數首先得引用System.Runtime.InteropServices

private System.ComponentModel.Container components = null;
  [DllImport("kernel32")]
  public static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
  [DllImport("kernel32")]
  public static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);

//聲明API

WritePrivateProfileString("Database Setting","Server",this.data_server,filename);

//讀取INI文件,("Database Setting"爲節點,"Server"爲節點的一個子項名,this.data_server接受"Server"子項的值,filename是INI文件的路徑);

StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString("Database Setting","Server","",temp,255,filename);

//同上,TEMP讀取的是"server"的值,

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章