现在我定义了一个静态类,通过此类访问非托管的第三方接口 public static class CBurdentVillageAPI
{
/// <summary>
/// 初始化
/// </summary>
/// <param name="ptr">可执行程序句柄</param>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int init(IntPtr ptr); /// <summary>
/// 打开交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int open(); /// <summary>
/// 交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int service(); /// <summary>
/// 关闭交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int close(); /// <summary>
/// 返回错误信息 dll接口任何调用异常,可以使用该函数来返回错误信息
/// </summary>
[DllImport("business.dll")]
public static extern void geterrormessage(StringBuilder tradereturnmsg);
}
程序中是这样调用的 public class CBurdentVillage :IDisposable
{
public bool GetPatiInfoForPati_Out_Visit(ref Global.strDaten dataset)
{
CBurdentVillageAPI.open();
...//省略参数传递
int Ret = CBurdentVillageAPI.service();
if (Ret != 0)
{
StringBuilder err = new StringBuilder(255);
CBurdentVillageAPI.geterrormessage(err);
DBPub.DataObj.ErrDes = err + "";
CBurdentVillageAPI.close();
return false;
}
else
{
...
}
}
}
#region IDisposable 成员
private bool m_disposed; void IDisposable.Dispose()
{
//throw new NotImplementedException();
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!m_disposed)
{
if (disposing)
{
//在这里释放托管对象 }
//在这里释放非托管对象
此处该如何操作????? m_disposed = true;
}
} ~CBurdentVillage()
{
Dispose(false);
}
现在我想问一下,程序调用完成后该如何释放这个非托管的资源呢
{
/// <summary>
/// 初始化
/// </summary>
/// <param name="ptr">可执行程序句柄</param>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int init(IntPtr ptr); /// <summary>
/// 打开交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int open(); /// <summary>
/// 交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int service(); /// <summary>
/// 关闭交易
/// </summary>
/// <returns></returns>
[DllImport("business.dll")]
public static extern int close(); /// <summary>
/// 返回错误信息 dll接口任何调用异常,可以使用该函数来返回错误信息
/// </summary>
[DllImport("business.dll")]
public static extern void geterrormessage(StringBuilder tradereturnmsg);
}
程序中是这样调用的 public class CBurdentVillage :IDisposable
{
public bool GetPatiInfoForPati_Out_Visit(ref Global.strDaten dataset)
{
CBurdentVillageAPI.open();
...//省略参数传递
int Ret = CBurdentVillageAPI.service();
if (Ret != 0)
{
StringBuilder err = new StringBuilder(255);
CBurdentVillageAPI.geterrormessage(err);
DBPub.DataObj.ErrDes = err + "";
CBurdentVillageAPI.close();
return false;
}
else
{
...
}
}
}
#region IDisposable 成员
private bool m_disposed; void IDisposable.Dispose()
{
//throw new NotImplementedException();
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!m_disposed)
{
if (disposing)
{
//在这里释放托管对象 }
//在这里释放非托管对象
此处该如何操作????? m_disposed = true;
}
} ~CBurdentVillage()
{
Dispose(false);
}
现在我想问一下,程序调用完成后该如何释放这个非托管的资源呢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货