读取配置文件
#region 公共方法读取配置文件
[DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, String filePath);
[DllImport("kernel32")] private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
/// <summary>
/// 读取配置文件方法
/// </summary>
/// <param name="father"></param>
/// <param name="child"></param>
/// <returns></returns>
public string GetConfigureInfo(string father, string child)
{
string data = "";
StringBuilder temp = new StringBuilder(255);
//ini文件路径
string strCom = System.Environment.CurrentDirectory + "\\com.ini";
GetPrivateProfileString(father, child, "读取文件失败", temp, 255, strCom);
if (temp.ToString().Trim() != "" && temp.ToString().Trim() != "读取文件失败")
{
data = temp.ToString().Trim();
}
else
{
MessageBox.Show("本地没有配置" + father + "的" + child + "相关信息");
}
return data;
}