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