#region 定义调用Delphi写的画图DLL
///
/// 定义调用Delphi写的画图DLL
///
private class DrawChartFromDll
{
//定义DLL文件名,此文件路径要加到系统Path中
private const string _fileDll = @"Chart.dll";
//调用非托管Dll,GetChartFromXMLByNet是ChartAccess.dll公开的函数名称
[DllImport(_fileDll, EntryPoint = "GetChartFromXMLByNet",
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
//C#中的申明
public static extern int GetChartFromXMLByNet(int piChartType,
string psXMLFileName, string psPriChartFileName, string psSecChartFileName,
string psPriHotFileName, string psSecHotFileName);
}
#endregion
public ChartResultData GetCharts(ChartData _ChartData,
Hashtable _HotPriAdditionSeqNo, Hashtable _HotSecAdditionSeqNo)
{
//根据数据生成XML文件
string _xmlFileName = "";
ChartResultData _ChartResultData = new ChartResultData();
try
{
_xmlFileName = this.ConvertDataToXml(_ChartData);
}
catch (Exception err)
{
_ChartResultData.ErrMessage = err.Message;
}
...
//调用DELPHI,取得返回参数
int _return = -1;
try
{
_return = DrawChartFromDll.GetChartFromXMLByNet(m_chartType, _xmlFileName,
_priChartFileName, _secChartFileName, _priHotFileName, _secHotFileName);
}
catch (Exception err)
{
if (_return > 0)
{
//删除临时生成的XML文件
this.DeleteTempFile(_xmlFileName);
this.DeleteTempFile(_priChartFileName);
this.DeleteTempFile(_secChartFileName);
this.DeleteTempFile(_priHotFileName);
this.DeleteTempFile(_secHotFileName);
_ChartResultData.ErrMessage = err.Message;
return _ChartResultData;
}
else
{
//可能因为安全性问题,在频繁连续调用DLL方法时有可能出现內存保护错误信息,虽然出错,
但方法已经正确调用并能返回正确的值,此时可以忽略此错误
_return = 0;
}
}
//删除临时生成的XML文件
this.DeleteTempFile(_xmlFileName);
...
}