本示例使用设备:https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.52de2c1b5P5rkA&ft=t&id=22173428704
[DllImport("kernel32", CharSet = CharSet.Unicode)]
public static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
public static string sGetINI(string strPath, string strSection, string strKey, string strDefault) {
StringBuilder returnString = new StringBuilder(255); // 返回值存储区
uint bufferSize = (uint)returnString.Capacity;
uint result = GetPrivateProfileString(strSection, strKey, strDefault, returnString, bufferSize, strPath);
return returnString.ToString();
}
private void Form20_Load(object sender, EventArgs e){
textBox26.Text = sGetINI("./syssetup.ini", "DefaultSetup", "HttpAccessFile", "IC-14.asp");
comboBox13.SelectedIndex = int.Parse(sGetINI("./syssetup.ini", "DefaultSetup", "HttpAccessMode", "0"));
WebPort.Value = int.Parse(sGetINI("./syssetup.ini", "DefaultSetup", "HttpAccessPort", "88"));
}
private void Form20_FormClosed(object sender, FormClosedEventArgs e) {
WritePrivateProfileString("DefaultSetup", "HttpAccessFile", textBox26.Text,"./syssetup.ini");
WritePrivateProfileString("DefaultSetup", "HttpAccessMode", comboBox13.SelectedIndex.ToString(),"./syssetup.ini");
WritePrivateProfileString("DefaultSetup", "HttpAccessPort", WebPort.Value.ToString(),"./syssetup.ini");
}