티스토리 뷰

C#

ini 파일 설정2

갱생쌩유 2012. 7. 5. 09:31

C#에서 ini 파일을 R/W 하기 위해서는 비관리 함수를 extern으로 가져와야 한다.

#region DllImport 사용 ini 파일에서 정보 가져오거나 Write하기
public class iniRW
{
public static string m_sFilePath = @"C:\TEST\Table.ini";
[DllImport("kernel32.dll")]
public static extern int GetPrivateProfileString(
string section,
string key,
string def,
StringBuilder retVal,
int nSize,
string lpFilePath);

[DllImport("kernel32.dll")]
public static extern long WritePrivateProfileString(
string section,
string key,
string val,
string lpFilePath);
}

#endregion

// ReadINI
public string ReadINI(string sID, string sKey, string sDef="")
{
if (!System.IO.File.Exists(iniRW.m_sFilePath)) return null;

StringBuilder sb = new StringBuilder(1024);
iniRW.GetPrivateProfileString(sID, sKey, sDef, sb, sb.Capacity, iniRW.m_sFilePath);
return sb.ToString();
}

// WriteINI
public bool WriteINI(string sID, string sKey, string sVal)
{
if (!System.IO.File.Exists(iniRW.m_sFilePath)) return false;
iniRW.WritePrivateProfileString(sID, sKey, sVal, iniRW.m_sFilePath);
return true;
}

'C#' 카테고리의 다른 글

C# 소켓 서버와 클라이언트를 통한 DB 검색  (0) 2012.07.12
dataGridView에 DB Select만 불러오기  (0) 2012.07.09
listview column 클릭 시 정렬하기  (0) 2012.07.05
String, StringBuilder  (0) 2012.07.05
ini 파일 설정  (0) 2012.07.05
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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 31
글 보관함