读写入INI文件
引用写入dll
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
写入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);
}
引用读取dll
[DllImport("kernel32.dll")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string INIPath);
调用
StringBuilder temp = new StringBuilder(500);
GetPrivateProfileString("CONFIG", "Player", "", temp, 500, ".\CONFIG.INI");
Player = temp.ToString();