VB6下标超出范围-但这是一个奇怪的问题,因为镜像函数工作正常

VB6下标超出范围-但这是一个奇怪的问题,因为镜像函数工作正常,vb6,Vb6,谢谢你的阅读 我已经构建了一个VB6 DLL(VB#U接口只是一个名称),它与一个C#DLL(C#U驱动程序只是一个名称)对话,C#DLL与蓝牙设备对话 我在第一阶段创建的演示VB6测试应用程序(VB_Demo只是为了一个名字)运行良好,达到了预期的效果。它调用VB_接口并打开和关闭BTU设备。其他功能也可以正常工作 但是,当将VB_接口中的操作代码放入另一个DLL(即实时操作DLL)时,Open可以正常工作,但Close会抛出错误。从C#U驱动程序返回时“变量未定义” 我就是不明白为什么,代码

谢谢你的阅读

我已经构建了一个VB6 DLL(VB#U接口只是一个名称),它与一个C#DLL(C#U驱动程序只是一个名称)对话,C#DLL与蓝牙设备对话

我在第一阶段创建的演示VB6测试应用程序(VB_Demo只是为了一个名字)运行良好,达到了预期的效果。它调用VB_接口并打开和关闭BTU设备。其他功能也可以正常工作

但是,当将VB_接口中的操作代码放入另一个DLL(即实时操作DLL)时,Open可以正常工作,但Close会抛出错误。从C#U驱动程序返回时“变量未定义”

我就是不明白为什么,代码是一样的,过程只是略有不同。我的意思是

在VB_演示中,我有两个按钮“打开”和“关闭”,当我点击这些按钮时,我会得到来自BTU设备的反馈

Private Sub btnOpenPort_Click()

'MsgBox steps(0)
    ReDim steps(5)

    Dim rc As HF4000_ResultCodes
    'rc = driver.OpenSerial(cmbPorts.Text)

    If driver.OpenSerial(cmbPorts.Text) = True Then


Private Sub btnClosePort_Click()

    Dim rc As HF4000_ResultCodes

    If driver.CloseSerial("COM4") = True Then
但是,在live DLL中,它只在内部执行相同的函数,而不需要通过单击按钮启动

' See IScanDevice documentation.
' @see IScanDevice#OpenDevice
Private Function IScanDevice_OpenDevice() As Scanning.Scan_ResultCodes
          (truncated slightly)
50      If driver.OpenSerial("COM4") = True Then
            rc = READY
            MsgBox "Connected to the device successfully."


' See IScanDevice documentation.
' @see IScanDevice#CloseDevice
Private Function IScanDevice_CloseDevice() As Scanning.Scan_ResultCodes
            (truncated slightly)
50        If driver.CloseSerial("COM4") = True Then
60          rc = READY
70          IScanDevice_CloseDevice = Scan_Success
clsDriver.cls

Public Event OnStateChanged(newState As String)

Public Event OnDataUpdated()

Dim WithEvents CSharpInteropServiceEvents As CSharpInteropService.LibraryInvoke
Dim load As New LibraryInvoke


Private Sub Class_Initialize()
  Set CSharpInteropServiceEvents = load
End Sub

Private Sub CSharpInteropServiceEvents_MessageEvent(ByVal newState As String)

   If newState = "OpenForm1" Then
   '   FormDummy2.Show  ' Not required
   End If

  If State <> newState Then
    State = newState
    RaiseEvent OnStateChanged(State)
    GetDriverData
  End If

End Sub

Private Function BluetoothTestInvoke(load, functionName, param)
    BluetoothTestInvoke = load.GenericInvoke("BluetoothTest.dll", "BluetoothTest.Class1", functionName, param)
End Function

Function OpenSerial(portNumber)   '   "COM4"
  Dim param(0) As Variant
  Dim retorno As Variant

  param(0) = portNumber
  retorno = BluetoothTestInvoke(load, "OpenSerial", param)

  OpenSerial = retorno(0)    <<<<<<<  Works fine returns TRUE

End Function

Function CloseSerial(portNumber)   '   "COM4"
  Dim param(0) As Variant
  Dim retorno As Variant

  param(0) = portNumber
  retorno = BluetoothTestInvoke(load, "CloseSerial", param)

  CloseSerial = retorno(0)    <<<<<<<<< "Error Subscript Out of Range"

End Function
公共事件OnStateChanged(新闻状态为字符串)
公共事件OnDataUpdate()
使用事件CSharpInteropService事件作为CSharpInteropService.LibraryInvoke调暗
新库启动时调暗负载
私有子类_Initialize()
设置CSharpInteropServiceEvents=load
端接头
私有子CSharpInteropServiceEvents_MessageEvent(ByVal newState作为字符串)
如果newState=“OpenForm1”,则
“FormDummy2.Show”不是必需的
如果结束
如果是国家新闻局的话
状态=新闻状态
RaiseEvent OnStateChanged(状态)
GetDriverData
如果结束
端接头
私有函数BluetoothTestInvoke(加载、函数名、参数)
BluetoothTestInvoke=load.GenericInvoke(“BluetoothTest.dll”、“BluetoothTest.Class1”、functionName、param)
端函数
函数OpenSerial(端口号)“COM4”
尺寸参数(0)作为变量
Dim Returno作为变体
参数(0)=端口号
returno=BluetoothTestInvoke(加载“OpenSerial”,参数)

OpenSerial=returno(0)一个建议是进行一些防御性编程。假设
retino
包含一个数组。不要做这种假设。在访问元素0之前,请确保它存在。这并不能说明它为什么不工作,但如果你这样做,至少不会崩溃。有点随机猜测,但是你是否进行了干净的重建,并确保没有旧的COM DLL在错误的位置注册?只是为了确保您认为正在执行的所有代码都是这样?实际上,您是否能够在各自的调试器中运行C#和VB6代码,并在执行时对其进行逐步跟踪?这应该是可能的,并且可能会使一些未知的因素变得更加明显。@Uudddllrss谢谢大家的想法,是的,我也试过了,不行。只是回到这个结果上。根据@Brian M Stafford的提示,我开始深入挖掘C#库并找到了bug。我在上面的更新中提到过。一个建议是有点防御性的编程。假设
retino
包含一个数组。不要做这种假设。在访问元素0之前,请确保它存在。这并不能说明它为什么不工作,但如果你这样做,至少不会崩溃。有点随机猜测,但是你是否进行了干净的重建,并确保没有旧的COM DLL在错误的位置注册?只是为了确保您认为正在执行的所有代码都是这样?实际上,您是否能够在各自的调试器中运行C#和VB6代码,并在执行时对其进行逐步跟踪?这应该是可能的,并且可能会使一些未知的因素变得更加明显。@Uudddllrss谢谢大家的想法,是的,我也试过了,不行。只是回到这个结果上。根据@Brian M Stafford的提示,我开始深入挖掘C#库并找到了bug。我在上面的更新中提到过。
  param(0) = portNumber
  retorno = BluetoothTestInvoke(load, "CloseSerial", param)   <<  param was being reset in the external library.