728x90
반응형
WPF & C# - config.ini 파일 간단하게 쓰기, 읽기 ( 섹션 & 키 값을 아는 경우 / Section / Key / Value ) |
MainWindow.xaml.cs ( 섹션 & 키 값을 아는 경우 )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | class ClassINI { #region >> ini 파일 엑세스 // iniSet("AAA", "B1", "CCC"); // ini 파일에 쓰기 // iniGet("AAA", "B1"); // ini 파일에 읽기 // iniSet("AAA", null, null); 섹션 초기화 string iniPath = Environment.CurrentDirectory + @"\config.ini"; // ini 파일명 [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); // ini파일에 쓰기 public void iniSet(string _Section, string _Key, string _Value) { WritePrivateProfileString(_Section, _Key, _Value, iniPath); } // ini파일 값 가져오기 public string iniGet(string _Section, string _Key) { StringBuilder STBD = new StringBuilder(1000); GetPrivateProfileString(_Section, _Key, null, STBD, 5000, iniPath); return STBD.ToString().Trim(); } #endregion } | cs |
728x90
반응형