ini 파일 안의 모든 section 값과 해당하는 section의 모든 key 값을 한번에 가져오기 위한 소스
Form 클래스 안에
[DllImport("kernel32")]
static extern int GetPrivateProfileString(string Section, string Key,
string Value, StringBuilder Result, int Size, string FileName);
[DllImport("kernel32")]
static extern int GetPrivateProfileString(string Section, int Key,
string Value, [MarshalAs(UnmanagedType.LPArray)] byte[] Result,
int Size, string FileName);
[DllImport("kernel32")]
static extern int GetPrivateProfileString(int Section, string Key,
string Value, [MarshalAs(UnmanagedType.LPArray)] byte[] Result,
int Size, string FileName);
public string path;
public string[] GetSectionNames() // ini 파일 안의 모든 section 이름 가져오기
{
for (int maxsize = 500; true; maxsize *= 2)
{
byte[] bytes = new byte[maxsize];
int size = GetPrivateProfileString(0, "", "", bytes, maxsize, path);
if (size < maxsize - 2)
{
string Selected = Encoding.ASCII.GetString(bytes, 0, size - (size > 0 ? 1 : 0));
return Selected.Split(new char[] { '\0' });
}
}
}
public string[] GetEntryNames(string section) // 해당 section 안의 모든 키 값 가져오기
{
for (int maxsize = 500; true; maxsize *= 2)
{
byte[] bytes = new byte[maxsize];
int size = GetPrivateProfileString(section, 0, "", bytes, maxsize, path);
if (size < maxsize - 2)
{
string entries = Encoding.ASCII.GetString(bytes, 0, size - (size > 0 ? 1 : 0));
return entries.Split(new char[] { '\0' });
}
}
}