IniManager.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ProcedureComparer
  8. {
  9. public class IniManager
  10. {
  11. // ---- ini 파일 의 읽고 쓰기를 위한 API 함수 선언 ----
  12. [DllImport("kernel32.dll")]
  13. private static extern int GetPrivateProfileString( // ini Read 함수
  14. String section,
  15. String key,
  16. String def,
  17. StringBuilder retVal,
  18. int size,
  19. String filePath);
  20. [DllImport("kernel32.dll")]
  21. private static extern long WritePrivateProfileString( // ini Write 함수
  22. String section,
  23. String key,
  24. String val,
  25. String filePath);
  26. /// ini파일에 쓰기
  27. public void SetIniValue(string path, string section, string key, string value)
  28. {
  29. WritePrivateProfileString(section, key, value, path);
  30. }
  31. /// ini파일에서 읽어 오기
  32. public string GetIniValue(string path, string section, string key)
  33. {
  34. StringBuilder temp = new StringBuilder(2000);
  35. int i = GetPrivateProfileString(section, key, "", temp, 2000, path);
  36. return temp.ToString();
  37. }
  38. }
  39. }