谁能帮我解释下这个代码是怎么搞到值的?
string DBServer = BCPCommon.ReadINI( "DB ", "DBServer ", " ", INIPath + "\\BCP.ini ");//调用ReadINI方法
/*ReadINI方法*/
public static string ReadINI(string section, string key, string def, string filename)
{
StringBuilder temp = new StringBuilder(1024);
try
{
GetPrivateProfileString(section, key, def, temp, 1024, filename);//调用GetPrivateProfileString方法
return temp.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
temp = null;
}
}
/*GetPrivateProfileString方法*/
[DllImport( "kernel32 ")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
/*.ini文件*/
[DB]
DBServer=203.163.38.158
DBName=Northwind
UserID=sa
Password=sa
[Path]
BCPOutPath=c:\BCPDemo
BCPInPath=c:\BCPDemo
LogPath=c:\BCPDemo
[Flag]
Run=O
[Timer]
Interval=100
------解决方案--------------------ini只有一种格式...
[section]
key=value
....
你应该去看看相关的文档...不过也没什么必要了...除了兼容旧的系统ini已经没有应用的价值...