我有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
提前致谢
答案 0 :(得分:0)
MQTransaction.Commit
Set MQTransaction = Nothing
仍然不知道原因: - |