我正在尝试与使用FDTI 232RL的USB设备进行通信。我安装了驱动程序并将.dll调用集成到我的VB5代码中,效果很好。我想让它在VB.net上工作但我得到PInvokeStackImballance错误消息。在VB5中,我有以下代码序列:
Private Declare Function FT_ListDevices Lib "FTD2XX.DLL" (ByVal arg1 As Long, ByVal arg2 As String, ByVal dwFlags As Long) As Long
...
Dim strSerialNumber As String * 256
...
LoggerList.AddItem ("ListDevices by S/N")
If FT_ListDevices(0, strSerialNumber, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER) <> FT_OK Then
...
在VB.NET中:
Private Declare Function FT_ListDevices Lib "FTD2XX.DLL" (ByVal arg1 As Long, ByVal arg2 As String, ByVal dwFlags As Long) As Long
...
Dim strSerialNumber As Stringbuilder new = stringbuilder (" ",256)
...
LoggerList.AddItem ("ListDevices by S/N")
If FT_ListDevices(0, strSerialNumber, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER) <> FT_OK Then
...
错误发生在if语句中。我是否需要导入带导入的Dll(“FTD2XX.dll”)?我也尝试了Dim strSerialNumber(256) as char
,但这也不起作用。我工作错了吗?
答案 0 :(得分:2)
在VB5中,long
为32位,而在VB.Net中为64位。将函数中的参数从long
更改为int
,即VB.Net上的32位。
Private Declare Function FT_ListDevices Lib "FTD2XX.DLL" (ByVal arg1 As Integer, _
ByVal arg2 As String, ByVal dwFlags As Integer) As Integer