给你举个例子,读写INI文件的。
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
namespace AAAA
{
public class INIFileIO
{
[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);
public INIFileIO()
{
}
public static void INIWriteValue(string section,string key,string val,string filePath)
{
WritePrivateProfileString(section,key,val,filePath);
}
public static string INIReadValue(string section,string key,string filePath)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(section,key,"",temp,
255, filePath);
return temp.ToString();
}
}
其中一定要引用System.Runtime.InteropServices;