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;
}
'프로그래밍 > .Net' 카테고리의 다른 글
c# 소멸자 만들기 (0) | 2014.01.17 |
---|---|
delegate 활용 함수 콜.. (0) | 2014.01.17 |
많은 컨트롤을 배열에 넣어보자 (0) | 2014.01.17 |
C#에서 using 사용하기 (0) | 2014.01.17 |
C# 스레드사용시 메서드 이름이 필요합니다 (0) | 2014.01.17 |