| ■No44846 (たろ さん) に返信
> セクション名を指定して情報を取得する処理は、
> [DllImport("kernel32")]
> private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
> を使用して実現できているのですが、
> セクション名だけを取得する処理がわかりません。。
GetPrivateProfileString API だけでいけますよ。
http://msdn.microsoft.com/ja-jp/library/cc429779.aspx
// C#
[DllImport("kernel32", CharSet = CharSet.Auto)]
private static extern int GetPrivateProfileString(
string section,
string key,
string def,
char[] retVal,
int size,
string filePath);
static void Main(string[] args)
{
char[] buf = new char[1024];
int ret = GetPrivateProfileString(null, null, null, buf, buf.Length, "odbc.ini");
string sectionsText = new string(buf, 0, ret);
string[] sections = sectionsText.TrimEnd('\0').Split('\0');
// 内容確認
Array.ForEach(sections, Console.WriteLine);
}
'-----------------------------------------
' Visual Basic
Declare Auto Function GetPrivateProfileString Lib "kernel32" _
(ByVal section As String, _
ByVal key As String, _
ByVal def As String, _
<Out(), MarshalAs(UnmanagedType.LPTStr)> ByVal buf As String, _
ByVal size As Integer, _
ByVal file As String) As Integer
Sub Main()
Dim buf As String = StrDup(1024, vbNullChar)
Dim ret As Integer = GetPrivateProfileString(Nothing, Nothing, Nothing, buf, buf.Length, "odbc.ini")
Dim sections() As String = Left(buf, ret).TrimEnd(vbNullChar).Split(vbNullChar)
'内容確認
Array.ForEach(sections, AddressOf Console.WriteLine)
End Sub |