#region 读取ini文件方法
public void readini()
{
sPath = Application.StartupPath; // 获取ini文件路径 不用GetPath();
sFile = sPath+"\\config.ini"; // 路径+文件名
iniDeal inifile = new iniDeal(sFile);
// 读取ini文件内容
VoiceIP = inifile.IniReadValue("VOICE","ip");
VoicePort = Convert.ToInt32(inifile.IniReadValue("VOICE","port"));
ParamRelay = inifile.IniReadValue ("PARAM","seekrelay");
ParamFax = inifile.IniReadValue ("PARAM","seekfax");
DBIP = inifile.IniReadValue ("DB","ip");
voiceControl linkvoice = new voiceControl();
linkvoice.tcplink(myLink,VoiceIP,VoicePort);
}
#endregion
//类在这里
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace common
{
#region INI文件操作类
/// <summary>
/// inifile 的摘要说明。
/// </summary>
public class iniDeal
{
//文件INI名称路径
public string Path;
////声明读写INI文件的API函数
[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);
//类的构造函数,传递INI文件名
public iniDeal(string inipath)
{
//
// TODO: Add constructor logic here
//
Path = inipath;
}
/// <summary>
/// 写INI文件
/// </summary>
/// <PARAM name="节点名"></PARAM>
/// 节点名
/// <PARAM name="键名"></PARAM>
/// 键名
/// <PARAM name="值"></PARAM>
/// 值
//写INI文件
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.Path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <PARAM name="节点名"></PARAM>
/// <PARAM name="键名"></PARAM>
/// <PARAM name="Path"></PARAM>
/// <returns></returns>
//读取INI文件
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path);
return temp.ToString();
}
}
#endregion
}