Readini.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Text;
  2. using System.Runtime.InteropServices;
  3. namespace UPPPayDll
  4. {
  5. public class IniFile
  6. {
  7. public string path; //INI文件名 111
  8. public string HISIP;
  9. public string HISURL;
  10. public string HISauthorization;
  11. [DllImport("kernel32")]
  12. private static extern long WritePrivateProfileString(string section, string key,
  13. string val, string filePath);
  14. [DllImport("kernel32")]
  15. private static extern int GetPrivateProfileString(string section, string key, string def,
  16. StringBuilder retVal, int size, string filePath);
  17. //声明读写INI文件的API函数
  18. public IniFile()
  19. {
  20. try
  21. {
  22. //path = System.IO.Directory.GetCurrentDirectory() + @"\PosConfigure.ini";
  23. path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\PosConfigure.ini";
  24. if (System.IO.File.Exists(path) == false)
  25. {
  26. path = "C://ProgramData//XYS//XYSService//plugins//ReadYBCard//PosConfigure.ini";
  27. }
  28. }
  29. catch (System.Exception)
  30. {
  31. path = "C://ProgramData//XYS//XYSService//plugins//ReadYBCard//PosConfigure.ini";
  32. }
  33. }
  34. //类的构造函数,传递INI文件名
  35. //写INI文件
  36. public void IniWriteValue(string Section, string Key, string Value)
  37. {
  38. WritePrivateProfileString(Section, Key, Value, this.path);
  39. }
  40. //读取INI文件指定
  41. public string IniReadValue(string Section, string Key)
  42. {
  43. StringBuilder temp = new StringBuilder(255);
  44. int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
  45. return temp.ToString();
  46. }
  47. public string IniReadLogPath()
  48. {
  49. return IniReadValue("LOG", "path");
  50. }
  51. }
  52. }