|
读取ini文件
- [DllImport("kernel32.dll")]
- private static extern long GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
- public static string GetKeys(string lpAppName, string lpKeyName, string lpDefault, string iniFile)
- {
- StringBuilder returnString = new StringBuilder(1024);
- if (File.Exists(iniFile))
- {
- long res = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, returnString, 1024, iniFile);
- }
- return returnString.ToString();
- }
复制代码 调用
- string exepath = Application.StartupPath;
- string x = IniFileOperator.GetKeys("App_Setting", "x", "", exepath + @"/" + "config.ini");
- string path = IniFileOperator.GetKeys("App_Setting", "path", "", exepath + @"/" + "config.ini");
- this.textBox1.Text = x;
- this.textBox2.Text = path;
复制代码 ini文件:
- #
- [App_Setting]
- x=1
- path=D:\994-WiTiAi\ReadIniFile\ReadIniFile\bin\Debug
复制代码
|
|