01using System.Runtime.InteropServices;
02using Microsoft.Win32;
03 
04//ini파일 입출력
05public class IniReadWrite
06{
07      // ---- ini 파일 의 읽고 쓰기를 위한 API 함수 선언 ----
08      [DllImport("kernel32.dll")]
09      private static extern int GetPrivateProfileString(    // ini Read 함수
10                  String section,
11                  String key,
12                  String def,
13                  StringBuilder retVal,
14                  int size,
15                  String filePath);
16 
17      [DllImport("kernel32.dll")]
18      private static extern long WritePrivateProfileString(  // ini Write 함수
19                  String section,
20                  String key,
21                  String val,
22                  String filePath);
23       
24      /// ini파일에 쓰기
25      public void G_IniWriteValue(String Section, String Key, String Value, string avsPath)
26      {
27          WritePrivateProfileString(Section, Key, Value, avsPath);
28      }
29 
30      /// ini파일에서 읽어 오기
31      public String G_IniReadValue(String Section, String Key, string avsPath)
32      {
33          StringBuilder temp = new StringBuilder(2000);
34          int i = GetPrivateProfileString(Section, Key, "", temp, 2000, avsPath); 
35          return temp.ToString();
36      }
37}
Posted by 아르다