我有一个旧的vb6程序,我需要在vb.net上使用它
我一直试图解决这个问题,但无法修复它! 我有一个用于阅读的dll文件和旧的rfdi读卡器(RF20E称为) 我已经设法将它用于阅读卡片,但是当涉及到扇形阅读时,它就失败了! 这是vb6的函数声明
Declare Function rf_read_hex Lib "rf20e.dll" (ByVal icdev As Long, ByVal Adr%, ByVal sdata As String) As Integer
这是vb6中的函数调用
Dim databuff32 As String * 32
address = 4
sector = 1
loadmode = 0
st = rf_authentication(ByVal icdev, loadmode, sector)
If st <> 0 Then
M1_label.Caption = "Call rf_authentication() error.Exit!"
Exit Sub
End If
st = rf_read_hex(ByVal icdev, address, databuff32)
If st <> 0 Then
M1_label.Caption = "Call rf_read_hex error.Exit!"
Exit Sub
End If
上面的代码工作得很好
这是.h库函数
__int16 __stdcall rf_read_hex(HANDLE icdev,unsigned char _Adr, char *_Data);
但是当我尝试在vb.net中做同样的事情时,我得到了受保护的内存错误
这是我的代码
Public Declare Function rf_read_hex Lib "rf20e.dll" (ByVal icdev As Integer, ByVal Adr%, ByRef sdata() As Char) As Short
Dim sector As Integer = 1
Dim address As Integer = 4
Dim loadmode = 0
st = rf_authentication(icdev, loadmode, sector)
st2 = rf_read_hex(icdev, address, databuff32)
rf_authentication工作正常!
我尝试了不同类型的databuff32 - 字节字符串字符串,但我要么输入类型错误或内存错误!
然而,当我将type设置为:Dim databuff32 As Char
并且在减速功能中将引用设置为ByRef sdata As Char
它可以工作但是!!!!!我只能读取第一个值
我很确定问题是字符串* 32减速但我无法解决它!
感谢您的帮助!
答案 0 :(得分:1)
这是有效的声明:
Public Declare Function rf_read_hex Lib "rf20e.dll" (ByVal icdev As Integer, ByVal adr As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal sdata As StringBuilder) As Short
这是电话:
Dim databuff32 As New StringBuilder(64)
st2 = rf_read_hex(icdev, address, databuff32)