在开发中,对INI文件的读写操作。
引用读写入dll
//写入
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
//读取
[DllImport("kernel32.dll")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string INIPath);
写入ini
public void IniWriteValue(string Section, string Key, string Value)
{
string inipath = ".CONFIG.INI";
WritePrivateProfileString(Section, Key, Value, inipath);
}
public void IniWriteValues() {
IniWriteValue("CONFIG", "Comport", ComPort);
}
读取ini
StringBuilder temp = new StringBuilder(500);
GetPrivateProfileString("CONFIG", "Player", "", temp, 500, ".CONFIG.INI");
Player = temp.ToString();