I have activex dll which has code for message queue, read and write from remote as well as local machine. i did some changes for reading messages from remote queue and tested that dll with sample form application. which works fine however when i copied this dll to my test machine (in actual application) i am facing "runtime error 91 object variable or With block variable not set" error
if i revert my changes its working fine
code after changes
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
code before changes
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
Thanks in advance