반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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 30
Archives
Today
Total
관리 메뉴

폴크(FOLC)

C# 테크닉 - 파일 제어( INI format ) 본문

C#, WF, WPF(.NET)/C#, WF, WPF(.NET) 테크닉

C# 테크닉 - 파일 제어( INI format )

folcjin 2021. 11. 29. 21:56
728x90
반응형

# WPF 를 이용하는 과정에서 HDD 에 존재하는 파일 ( ini format ) 제어
   > Save, Load 형태 - DllImport("kernel32") 이용
   > exe 파일 위치에 test.ini 파일 생성

# 소스 코드
using System.Runtime.InteropServices;

public class INIformat
{
   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);

   public void WriteReadTest()
   {
     
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

      path = System.IO.Path.GetDirectoryName(path) + "\\test.ini";
      
      WritePrivateProfileString("SECTION", "KEY1", "VALUE1", path);

      StringBuilder retVal = new StringBuilder();
      GetPrivateProfileString("SECTION", "KEY1", "def", retVal, 32, path);
   }

728x90
반응형
사업자 정보 표시
사업자 등록번호 : -- | TEL : --