网上有n多关于
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key,string val,string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key,string def, StringBuilder retVal,
int size,string filePath);
这两个function的介绍。
现在想要取ini文件节里的所有key和value列表就找到了这个
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int GetPrivateProfileSectionA ( string lpAppName, [MarshalAs(UnmanagedType.LPArray)] byte[] lpReturnedString, int nSize, string lpFileName) ;
网上有介绍,这里要记的是它取回的lpReturnedString里分隔符是(Char)0,这个可是String类型的结尾符,只能做个处理
byte[] b = new byte[102400];
GetPrivateProfileSectionA("test", b, int.MaxValue, @"D:/test/aa.ini");
string s = "";
for(int i = 0; i <= b.Length - 1; i++)
{
if (b[i] != 0)
{
s += (char)b[i];
}
else
{
if (s[s.Length -1] != '~')
{
s += "~";
}
}
}
给它换成以~分隔的string再做它用,麻烦!!
ini文件的控制
最新推荐文章于 2024-10-31 19:12:34 发布