using System.Runtime.InteropServices;
[DllImport("kernel32")] //调用kernel32.dll读取ini文件中的内容
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")] //调用kernel32.dll写ini文件中的内容
private static extern bool WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
public const string FILE_NAME = "..//login.ini"; //ini文件路径
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();
}
//读ini
public static string fwq = IniReadValue("jd126", "服务器", "..//login.ini").ToString().Trim();
public static string uid = IniReadValue("jd126", "用户", "..//login.ini").ToString().Trim();
public static string pwd = IniReadValue("jd126", "密码", "..//login.ini").ToString().Trim();
/ /写ini
WritePrivateProfileString("jd126", "服务器", this.server.Text.ToString(), FILE_NAME);
WritePrivateProfileString("jd126", "用户", this.uid.Text.ToString(), FILE_NAME);
WritePrivateProfileString("jd126", "密码", this.pwd.Text.ToString(), FILE_NAME);