http://blog.163.com/da7_1@126/blog/static/104072678201311721326318/
以下代码为本人在实际项目中编写的调用第三方DLL接口程序的完整代码。
public class ExecuteDLL : Form
{
...//忽略与调用DLL无关的代码
private IntPtr hModule = IntPtr.Zero;
/// <summary>
/// 调用HIS系统提供的DLL接口程序查看检查申请单
///DLL的名称:H62AppQueryToPacs.dll
///函数名说明:
///function THandle HLoginProc(THandlea AppHandle, THandle aCallWinHandle,THandle aPluginHandle
/// PChar aBqno,PChar aEmpno,PChar aPatno);
///传入变量参数说明:
///// aAppHandle: THandle; //应用程序句柄
///// aCallWinHandle: THandle; //调用窗口句柄
///// aPluginHandle: THandle; // 插件的句柄
///// aEmpno,PChar;//医生工号
///// aBqno: PChar;//病区代码
///// aPatno: PChar;//病人记账号
/// </summary>
/// <param name="lpFileName"></param>
/// <returns></returns>
//申明外部API
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32", EntryPoint = "FreeLibrary", SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);
//申明委托
private delegate IntPtr HLoginProc(IntPtr aAppHandle, IntPtr aCallWinHandle, IntPtr aPluginHandle,
string aBqno, string aEmpno, string aPatno);
//获取函数地址
private Delegate GetFunctionAddress(IntPtr dllModule, string functionName, Type t)
{
IntPtr address = GetProcAddress(dllModule, functionName);
if (address == IntPtr.Zero)
return null;
else
return Marshal.GetDelegateForFunctionPointer(address, t);
}
//按钮单击事件
private void button_CheckList_Click(object sender, EventArgs e)
{
try
{
SIS_Model.MWorkList smWorkList;
PACS_Model.MWorkList pmWorkList;
string strNo = "";
switch (GetConfig.DALAndModel)
{
case "SIS":
smWorkList = (SIS_Model.MWorkList)this.iWorkList;
strNo = (smWorkList.INPATIENTNO == null ? "" : smWorkList.INPATIENTNO.ToString());// 病人记账号 "875624";
break;
case "PACS":
pmWorkList = (PACS_Model.MWorkList)this.iWorkList;
strNo = (pmWorkList.INPATIENTNO == null ? "" : pmWorkList.INPATIENTNO.ToString());// 病人记账号 "875624";
break;
}
if (strNo.Trim() == "")
{
MessageBox.Show("无法获取患者ID,请确认操作步骤是否正确");
return;
}
//加载DLL
try
{
string strDLLPath = Environment.CurrentDirectory + "\\HuiTong\\JianChaShenQingDan\\H62AppQueryToPacs.dll";
hModule = LoadLibrary(strDLLPath);
if (hModule.Equals(IntPtr.Zero))
{
MessageBox.Show("导入DLL失败");
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
FreeLibrary(hModule);
hModule = IntPtr.Zero;
return;
}
//将要调用的方法转换为委托:hModule为DLL的句柄,"HLoginProc"为DLL中方法的名称
HLoginProc farProc = (HLoginProc)this.GetFunctionAddress(hModule, "HLoginProc", typeof(HLoginProc));
if (farProc == null)
{
FreeLibrary(hModule);
hModule = IntPtr.Zero;
return;
}
//利用委托执行DLL文件中的接口方法
farProc(hModule, IntPtr.Zero, IntPtr.Zero, null, null, strNo);
FreeLibrary(hModule);
hModule = IntPtr.Zero;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
FreeLibrary(hModule);
hModule = IntPtr.Zero;
return;
}
}
}
- Java调用第三方dll文件的使用方法 System.load()或System.loadLibrary()
Java调用第三方dll文件的使用方法 public class OtherAdapter { static { //System.loadLibrary("Connector") ...
- C# 调用第三方DLL完整实例
C# 调用第三方DLL完整实例 分类: C/C++ 以下代码为本人在实际项目中编写的调用第三方DLL接口程序的完整代码. public class ExecuteDLL : Form { ...//忽 ...
- C# 调用第三方DLL缓冲区溢出导致的异常
这个倒是少见的错误,纪录一下大佬. 先上异常 错误一:尝试读取或写入受保护的内存 错误二:未将对象引用设置到对象的实例 错误三: 托管调试助手“FatalExecutionEngineError”( ...
- dotnetnuke 调用第三方dll出错 System.Security.Permissions.SecurityPermission,型的权限已失败。
在dnn下调用第三方dll的微信sdk ,代码如下: WebClient wc = new WebClient(); wc.Encoding = encoding ?? Encoding.UTF8; ...
- SOE 中调用第三方dll
一.简介 在利用soe实现server的扩展的时候,有些时候,需要调用第三方的dll库.官网中给出了明确的说明,soe中是可以添加第三方的dll文件,但是一直没有测试.按照官方的步骤应该是一个非常的简 ...
- Java调用C/C++编写的第三方dll动态链接库(zz)
这里主要用的方法是JNI.在网上查资料时看到很多人说用JNI非常的复杂,不仅要看很多的文档,而且要非常熟悉C/C++编程.恐怕有很多人在看到诸如此类的评论时已经决定绕道用其他方法了.本文将做详细的介绍 ...
- 引用第三方dll引发的问题解决
引用的程序集错误 如果引用第三方dll,调试出现引用的程序集出现错误,可以下载dependency,查看这个dll的依赖dll,如果本地电脑没有依赖dll或依赖dll出现问题,则下载或取代依赖dll ...
- C#的Process类调用第三方插件实现PDF文件转SWF文件
在项目开发过程中,有时会需要用到调用第三方程序实现本系统的某一些功能,例如本文中需要使用到的swftools插件,那么如何在程序中使用这个插件,并且该插件是如何将PDF文件转化为SWF文件的呢?接下来 ...
- c# 调用c++DLL方法及注意事项
引用命名空间 using System.Runtime.InteropServices 调用方法: 一.静态加载 用DllImprot方式来加载c++DLL.如下格式: //对应c++方法 //voi ...
随机推荐
- P4294 [WC2008]游览计划
传送门 斯坦纳树 给一个联通图,求 $k$ 个关键点联通的最小生成树权值 设 $f[o][i]$ 表示当前关键点选择状态为 $o$ ,以点 $i$ 为根的树的最小权值 初始 $f[1<<( ...
- Mutation and Iteration
avoid mutating a list as you are iterating over it 代码: def remove_dups(L1,L2): for e in L1: if e in ...
- 关于jstl taglib的错误 Can not find the tag library descriptor for “http://java.sun.com/jstl/core”
在查了N个帖子之后,决定记录一下关于jstl taglib的配置方法. 首先我遇到的错误是: Can not find the tag library descriptor for "htt ...
- 墨菲定律&吉德林法则&吉尔伯特定律&沃尔森法则&福克兰定律
一.墨菲定律:越害怕什么,就越会发生什么 二.吉德林法则:把问题清楚地写下来,就已经解决一半了 三.吉尔伯特定律:工作中的最大问题就是没人跟你说该如何去做 四.沃尔森法则:把信息和情报排在第一位,金钱 ...
- 安装Drupal
我在虚拟机里面安装了Ubuntu Server 14.参考https://www.digitalocean.com/community/tutorials/how-to-install-drupal- ...
- 安装wine
sudo add-apt-repository ppa:ubuntu-wine/ppa sudo apt-get update sudo apt-get install winetricks
- 【ExtJS】自定义组件datetimefield(二)
接上[ExtJS]自定义组件datetimefield(一) 第三步:添加按钮事件绑定,获取选定的时间 privates:{ finishRenderChildren: function () { v ...
- mysql用户操作
一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指 ...
- win10的xbox下载应用或者游戏时,出现0x80070422和0x80073D0A的解决办法
这个错误:0x80070422是因为关闭了windows update这个服务导致的 这个错误:0x80073D0A是因为关闭了windows firewall这个服务导致的 具体操作: cmd下se ...
- sql查询时,根据特定的条件给表的某一个字段赋值
先讲一下需要这个需求的情景: 这是一个招聘求职项目遇到的一个问题.个人A向公司B的职位投递简历后,公司B会收到个人A的简历;但是A投递后把简历删除,公司收到的简历信箱 还有这个简历,但却不能看了. 原 ...