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"的值,