您的位置:首页 > 编程语言 > C语言/C++

C#读取ini文件方法,实质是使用C++的库

2016-01-28 19:54 711 查看
C#读取ini文件方法,实质是使用C++的库

[DllImport("kernel32")]
public static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);

//读取ini配置文件
public static string GetIniValue(string strFilePath, string key)
{
if (!File.Exists(strFilePath)) return string.Empty;
StringBuilder temp = new StringBuilder(1024);
string strSec = "GISDownLoad";
HVIC.Library.Win32API.GetPrivateProfileString(strSec, key, "", temp, 1024, strFilePath);
return temp.ToString();
}

//写入ini配置文件
public static void WriteIniValue(string strFilePath,string key,string value)
{
string strSec = "GISDownLoad";
if (!string.IsNullOrEmpty(value))
{
HVIC.Library.Win32API.WritePrivateProfileString(strSec, key, value.Trim(), strFilePath);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: