INIFile.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.IO;
  4. using System.ComponentModel;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. namespace Core.Mes.Common
  9. {
  10. public class INIFile
  11. {
  12. public string inipath;
  13. [DllImport("kernel32")]
  14. private static extern long WritePrivateProfileString(string section, string key,
  15. string val, string filePath);
  16. [DllImport("kernel32")]
  17. private static extern int GetPrivateProfileString(string section, string key,
  18. string def, StringBuilder retVal, int size, string filePath);
  19. public INIFile(string INIPath)
  20. {
  21. inipath = INIPath;
  22. }
  23. public void WriteValue(string section, string key, string value)
  24. {
  25. WritePrivateProfileString(section, key, value, inipath);
  26. }
  27. public string ReadValue(string section, string key)
  28. {
  29. StringBuilder temp = new StringBuilder(500);
  30. int length = GetPrivateProfileString(section, key, "", temp, 500, inipath);
  31. return temp.ToString();
  32. }
  33. }
  34. }