public class cls_ConfigRead
{
[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);
public static void WriteIni(string section, string key, string value, string iniPath)
{
WritePrivateProfileString(section, key, value, iniPath);
}
public static string ReaderIni(string section, string key, string iniPath)
{
try
{
StringBuilder temp = new StringBuilder(1024);
int i = GetPrivateProfileString(section, key, "", temp, 500, iniPath);
if (i == 0)
{
return null;
}
return temp.ToString();
}
catch
{
return null;
}
}
public static bool ExsitFile(string iniPath)
{
return File.Exists(iniPath);
}
}
string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config.ini";
if (!File.Exists(configPath))
{
MessageBox.Show("不存在配置文件:Config.ini");
this.Close();
}