VB6与VB.net调用dll的问题,急!
在vb.net环境下调用dll接口,对外围设备进行操作,没有问题,可以实现功能,具体函数说明及调用方法如下:
Dim result As Long
Declare Auto Function UCommand1 Lib "RdCard.dll " (ByRef pComd As Integer, ByRef parg0 As Integer, ByRef parg1 As Integer, ByRef parg2 As Integer) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
result = UCommand1(65, 0, 8811, 9986) '初始化
ListView1.Items.Add( "初始化结果: " & result.ToString)
Catch ex As Exception
MessageBox.Show( "初始化错误: " & ex.ToString)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
result = UCommand1(67, 0, 8811, 9986) '验卡
ListView1.Items.Add( "验卡结果: " & result.ToString)
result = UCommand1(68, 0, 8811, 9986) '读卡信息
ListView1.Items.Add( "读卡信息结果: " & result.ToString)
Catch ex As Exception
MessageBox.Show( "读卡错误: " & ex.ToString)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
result = UCommand1(66, 0, 8811, 9986) '关闭端口
ListView1.Items.Add( "关闭端口结果: " & result.ToString)
Catch ex As Exception
MessageBox.Show( "关闭端口错误: " & ex.ToString)
End Try
End Sub
然后将.net中的声明等复制到vb中,进行调用,代码如下:
Private Declare Function UCommand1 Lib "RdCard.dll " (ByRef pComd As Integer, ByRef parg0 As Integer, ByRef parg1 As Integer, ByRef parg2 As Integer) As Long
Private Sub Command1_Click()
Dim result As Long
result = UCommand1(65, 0, 8811, 9986)
List1.AddItem result
End Sub
Private Sub Command2_Click()
Dim result As Long
result = UCommand1(67, 0, 8811, 9986) '验卡
List1.AddItem result
result = UCommand1(68, 0, 8811, 9986) '读卡信息
List1.AddItem result
End Sub
但是调用不成功,返回值错误,无法使用外围设备。
求助高手帮忙解决一下此问题,是vb中调用和声明有问题?对vb调用dll还不是很熟悉,请各位帮忙,谢谢
[解决办法]
类型不一样了。如.net中的Integer中vb6中是long等
[解决办法]
恩。vb和vb.net的数据类型定义不同。