API调用如下:
Imports System.Text
Namespace CardReader.API
Public Class JingLunAPI
''' <summary>
''' 初始化函数
''' </summary>
''' <param name="port"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function InitComm Lib "sdtapi.dll" (ByVal port As Integer) As Integer
''' <summary>
''' 端口关闭接口
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function CloseComm Lib "sdtapi.dll" () As Integer
''' <summary>
''' 卡认证接口
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function Authenticate Lib "sdtapi.dll" () As Integer
''' <summary>
''' 读取卡信息
''' </summary>
''' <param name="pmsg"></param>
''' <param name="len"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function ReadBaseMsg Lib "sdtapi.dll" (ByVal pmsg As Byte(),ByRef len As Integer) As Integer
''' <summary>
''' 读取卡信息
''' </summary>
''' <param name="Name"></param>
''' <param name="Gender"></param>
''' <param name="Folk"></param>
''' <param name="BirthDay"></param>
''' <param name="Code"></param>
''' <param name="Address"></param>
''' <param name="Agency"></param>
''' <param name="ExpireStart"></param>
''' <param name="ExpireEnd"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function ReadBaseInfos Lib "sdtapi.dll" (ByVal Name As StringBuilder,ByVal Gender As StringBuilder,ByVal Folk As StringBuilder,ByVal BirthDay As StringBuilder,ByVal Code As StringBuilder,ByVal Address As StringBuilder,_
ByVal Agency As StringBuilder,ByVal ExpireStart As StringBuilder,ByVal ExpireEnd As StringBuilder) As Integer
''' <summary>
''' 读取卡信息,图片指定到目录(这个接口目录不能传应该程序根目录,不然生成不了图片;如果图片存在应用程序根目录调用上面的方法:ReadBaseInfos)
''' </summary>
''' <param name="Name"></param>
''' <param name="Gender"></param>
''' <param name="Folk"></param>
''' <param name="BirthDay"></param>
''' <param name="Code"></param>
''' <param name="Address"></param>
''' <param name="Agency"></param>
''' <param name="ExpireStart"></param>
''' <param name="ExpireEnd"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Declare Function ReadBaseInfosPhoto Lib "sdtapi.dll" (ByVal Name As StringBuilder,ByVal ExpireEnd As StringBuilder,ByVal directoryPath As String) As Integer
Public Declare Function ReadNewAppMsg Lib "sdtapi.dll" (ByVal pmsg As StringBuilder,ByRef len As Integer) As Integer
End Class
End Namespace
方法ReadBaseInfosPhoto 调用报错,如下:
正试图在 OS 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起
解决办法:
http://www.cnblogs.com/winzheng/archive/2008/12/05/1348575.html
来有一个问题:ReadBaseInfosPhoto方法的地址ByVal directoryPath As String,不能是:Byref directoryPath As String
因为:在VB中,应该申明为以Byval方式传递的String,因为VB中的字符串变量(变长的)实际存的就是字符串的指针。
原文链接:https://www.f2er.com/vb/260016.html