我正在尝试与使用 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 语句中。我是否需要使用 import("FTD2XX.dll") 导入 Dll?我也试过Dim strSerialNumber(256) as char
了,也不管用。我在解决错误的问题吗?