iniUtil.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace CLIP.eForm.Consent.UI
  7. {
  8. class iniUtil
  9. {
  10. private string iniPath;
  11. public iniUtil(string path)
  12. {
  13. this.iniPath = path; //INI 파일 위치를 생성할때 인자로 넘겨 받음
  14. }
  15. [DllImport("kernel32.dll")]
  16. private static extern int GetPrivateProfileString( // GetIniValue 를 위해
  17. String section,
  18. String key,
  19. String def,
  20. StringBuilder retVal,
  21. int size,
  22. String filePath);
  23. [DllImport("kernel32.dll")]
  24. private static extern long WritePrivateProfileString( // SetIniValue를 위해
  25. String section,
  26. String key,
  27. String val,
  28. String filePath);
  29. // INI 값을 읽어 온다.
  30. public String GetIniValue(String Section, String Key)
  31. {
  32. StringBuilder temp = new StringBuilder(255);
  33. int i = GetPrivateProfileString(Section, Key, "", temp, 255, iniPath);
  34. return temp.ToString();
  35. }
  36. // INI 값을 셋팅
  37. public void SetIniValue(String Section, String Key, String Value)
  38. {
  39. WritePrivateProfileString(Section, Key, Value, iniPath);
  40. }
  41. }
  42. }