1
我試圖與使用FDTI 232RL的USB設備進行通信。我已經安裝了驅動程序,並將.dll調用集成到了我的VB5代碼中,並且運行良好。我想讓這個工作在VB.net上,但我得到了PInvokeStackImballance錯誤消息。在VB5我有下面的代碼序列:從VB5移到VB.NET,並遇到USB .dll調用問題
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
,那也不管用。我工作錯了嗎?
謝謝。它不再「崩潰」,但通話不起作用。我會繼續努力,但你的評論是非常有幫助的 –