运行时错误91对象变量或使用块变量未在测试机器中设置vb6,但在开发机器中正常工作

时间:2016-04-14 13:13:32

标签: dll vb6

我有activex dll,它包含消息队列的代码,从远程和本地机器读取和写入。 我做了一些更改,从远程队列中读取消息,并使用示例表单应用程序测试了该DLL。 哪个工作正常 但是当我把这个dll复制到我的测试机器上时(在实际应用中) 我面临"运行时错误91对象变量或者没有设置块变量" 错误

如果我将我的更改恢复为正常工作

更改后的

代码

Private Function RetrieveMessage(ByVal MQReceive As msmq.MSMQQueue, _
MQTransaction As msmq.MSMQTransaction, _
ByVal Wait As Boolean, MessageLabel As String, MessageBody As String) As Boolean

'Dim MQReceive As MSMQ.MSMQQueue
Dim MQMsgRec As MSMQMessage
Dim MQDispenser As msmq.MSMQCoordinatedTransactionDispenser

On Error GoTo ErrorHandler

RetrieveMessage = False

If Not m_bQueueExists Then
    Err.Raise vbObjectError + 1, "MicrosoftMQImpl", "Queue " & m_sQueueName & _
    " does not exist"
Else
  Set MQDispenser = New msmq.MSMQCoordinatedTransactionDispenser
    'Begin Transaction
    Set MQTransaction = MQDispenser.BeginTransaction

    Dim bMessageFound As Boolean
    bMessageFound = False

    Set MQMsgRec = MQReceive.Receive(ReceiveTimeout:=IIf(Wait = True, DISPATCH_MESSAGE_INTERVAL, 0))

    'Set MQMsgRec = MQReceive.Receive(Transaction:=MQTransaction, _
       ' ReceiveTimeout:=IIf(Wait = True, DISPATCH_MESSAGE_INTERVAL, 0))

    If MQMsgRec Is Nothing Then
        bMessageFound = False
    Else
        bMessageFound = True
        MessageBody = CStr(MQMsgRec.Body)
        MessageLabel = CStr(MQMsgRec.Label)
    End If

    Set MQDispenser = Nothing
    Set MQMsgRec = Nothing

    RetrieveMessage = bMessageFound

    MQTransaction.Commit
    Set MQTransaction = Nothing

End If
Exit Function
ErrorHandler:
If Not (MQTransaction Is Nothing) Then
    MQTransaction.Abort
    Set MQTransaction = Nothing
End If
LogNTEvent "PHLMessaging:MicrosoftMQImpl:RetrieveMessage", Err.Description, eNTLog_Error
Err.Raise Err.Number, Err.Source, Err.Description
End Function

更改前的代码

Private Function RetrieveMessage(ByVal MQReceive As msmq.MSMQQueue, _
MQTransaction As msmq.MSMQTransaction, _
ByVal Wait As Boolean, MessageLabel As String, MessageBody As String) As Boolean

'Dim MQReceive As MSMQ.MSMQQueue
Dim MQMsgRec As MSMQMessage
Dim MQDispenser As msmq.MSMQTransactionDispenser

On Error GoTo ErrorHandler

RetrieveMessage = False

If Not m_bQueueExists Then
    Err.Raise vbObjectError + 1, "MicrosoftMQImpl", "Queue " & m_sQueueName & _
    " does not exist"
Else
Set MQDispenser = New msmq.MSMQTransactionDispenser
    'Begin Transaction
    Set MQTransaction = MQDispenser.BeginTransaction

    Dim bMessageFound As Boolean
    bMessageFound = False


    Set MQMsgRec = MQReceive.Receive(Transaction:=MQTransaction, _
        ReceiveTimeout:=IIf(Wait = True, DISPATCH_MESSAGE_INTERVAL, 0))

    If MQMsgRec Is Nothing Then
        bMessageFound = False
    Else
        bMessageFound = True
        MessageBody = CStr(MQMsgRec.Body)
        MessageLabel = CStr(MQMsgRec.Label)
    End If

    Set MQDispenser = Nothing
    Set MQMsgRec = Nothing

    RetrieveMessage = bMessageFound

End If
Exit Function
ErrorHandler:
If Not (MQTransaction Is Nothing) Then
    MQTransaction.Abort
    Set MQTransaction = Nothing
End If
LogNTEvent "PHLMessaging:MicrosoftMQImpl:RetrieveMessage", Err.Description, eNTLog_Error
Err.Raise Err.Number, Err.Source, Err.Description
End Function

提前致谢

1 个答案:

答案 0 :(得分:0)

我以某种方式设法解决了这个错误 刚刚在更改中注释了以下代码

MQTransaction.Commit
Set MQTransaction = Nothing

仍然不知道原因: - |