动态调用链接库(dll) 续
2024-09-06 18:35:23
20141118
最近一周做了一个关于仓库管理,拣货任务分配的模块,其中涉及到刷卡自动打印领取任务的功能点。
技术点:
C#调用C++、delphi的动态链接库。动态链接库的调用方法不同。效果也不相同。
DLL位置:执行程序根目录下面
例:
第一种:
[DllImport("shuipiao1.dll", EntryPoint = "checkticket", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
第二种:
[DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)]
第三种:
[DllImport("MifsDLL.dll", CharSet = CharSet.Ansi, EntryPoint = "mifs_anticoll", CallingConvention = CallingConvention.Cdecl)]
实际案例:
#region 调用dll接口方法
// 打开串口 OpenComm(char *commPort,DWORD baud) [DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)] // [DllImport("MifsDLL.dll", EntryPoint = "OpenComm", SetLastError = true,
//CharSet = CharSet.Auto, ExactSpelling = false,
//CallingConvention = CallingConvention.StdCall)] //打开串口
public static extern Int16 OpenComm(string port, long baud); //装载密钥 WINAPI mifs_load_key(uchar _Mode, uchar _SecNr, uchar *Key)
[DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)]
//打开串口
public static extern Int16 mifs_load_key(uint Mode, uint SecNr, byte[] Key); [DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)]
//mifs_request_2 寻卡
public static extern Int16 mifs_request_2(long mode); [DllImport("MifsDLL.dll", CharSet = CharSet.Ansi, EntryPoint = "mifs_anticoll", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 mifs_anticoll(uint Bcnt, byte[] port); //mifs_select(uchar *_Snr) [DllImport("MifsDLL.dll", CharSet = CharSet.Ansi, EntryPoint = "mifs_select", CallingConvention = CallingConvention.Cdecl)]
//选卡
public static extern Int16 mifs_select(byte[] port); //mifs_authentication(uchar auth_mode,uchar *snr,uchar key_sector)
[DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)]
//认证秘钥
public static extern Int16 mifs_authentication(uint mode, byte[] Snr, uint Key); //读卡数据 mifs_read(uchar _Adr, uchar *_Data) 出口函数16byte [DllImport("MifsDLL.dll", CharSet = CharSet.Ansi, EntryPoint = "mifs_read", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 mifs_read(uint Adr, byte[] Data); //int WINAPI mifs_write(uchar _Adr, uchar *_Data) 写员工号
[DllImport("MifsDLL.dll", CharSet = CharSet.Ansi)]
public static extern Int16 mifs_write(uint Adr, byte[] Data); // 蜂鸣 mifs_Buzzer(uchar bb)
[DllImport("MifsDLL.dll", EntryPoint = "mifs_Buzzer", SetLastError = true,
CharSet = CharSet.Auto, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern void mifs_Buzzer(int bb);
#endregion
最新文章
- (转)You might not need jQuery
- WebService的两种方式SOAP和REST比较 (转)
- 区间DP lightoj 1031
- NYOJ题目893十字架
- Oracle的内存结构
- iOS开发中一些常见的并行处理(转)
- Android Studio使用中的异常
- Stanford机器学习---第五讲. 神经网络的学习 Neural Networks learning
- MYSQL 5.7 主从复制 -----GTID说明与限制 原创
- js中邦定事件与解绑支持匿名函数
- js日期操作时间看板
- ";AWT-EventQueue-0"; java.lang.UnsatisfiedLinkError: no freetype in java.library.path
- PHP跨域jsonp方式
- shell 备份 source code
- RESTful restful api Representational State Transfer
- 快速构建springmvc+spring+swagger2环境
- 【Linux】人脸识别的封装
- python的ConfigParser模块
- 逆序对__归并排序__树状数组 Inversions SGU - 180
- JVM 学习集合