Hello Mat

 找回密码
 立即注册
查看: 5460|回复: 1

操作ini文件

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2020-12-6 13:28:25 | 显示全部楼层 |阅读模式

读取ini文件
  1.         [DllImport("kernel32.dll")]
  2.         private static extern long GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

  3.         public static string GetKeys(string lpAppName, string lpKeyName, string lpDefault, string iniFile)
  4.         {
  5.             StringBuilder returnString = new StringBuilder(1024);
  6.             if (File.Exists(iniFile))
  7.             {
  8.                 long res = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, returnString, 1024, iniFile);
  9.             }
  10.             return returnString.ToString();
  11.         }
复制代码
调用
  1.             string exepath = Application.StartupPath;
  2.             string x = IniFileOperator.GetKeys("App_Setting", "x", "", exepath + @"/" + "config.ini");
  3.             string path = IniFileOperator.GetKeys("App_Setting", "path", "", exepath + @"/" + "config.ini");
  4.             this.textBox1.Text = x;
  5.             this.textBox2.Text = path;
复制代码
ini文件:
  1. #
  2. [App_Setting]
  3. x=1
  4. path=D:\994-WiTiAi\ReadIniFile\ReadIniFile\bin\Debug
复制代码








算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-20 02:48 , Processed in 0.222090 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表