您的位置:首页 > 编程语言 > C#

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

2006-02-28 17:54 489 查看
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"的值,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: