티스토리 뷰
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 |