Sending messages consists of opening a queue with send access, creating the message, calling the Send method, and then closing the queue. The following procedure and example code show how this is done when sending a message whose body contains an array of bytes.
Dim qinfo As New MSMQQueueInfo
Dim qSend As MSMQQueue
Dim qReceive As MSMQQueue
Dim mSend As New MSMQMessage
Dim mReceive As MSMQMessage
qinfo.PathName = ".\SendTest"
qinfo.Label = "Send Message Test"
On Error Resume Next 'Ignore if queue already exists.
qinfo.Create
On Error GoTo 0
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
Dim aByte(5) As Byte
Dim Counter As Integer
'Populate the array
For Counter = LBound(aByte) To UBound(aByte)
aByte(Counter) = CByte(Counter)
Next
mSend.Label = "Byte Array Message"
mSend.Body = aByte
mSend.Send qSend
qSend.Close
Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set mReceive = qReceive.Receive
qReceive.Close
If TypeName(mReceive.Body) = "Byte()" Then
MsgBox "The retrieved message body is an array of bytes."
Else
MsgBox "The retrieved message body is not an array of bytes."
End If
The following example creates a destination queue, sends a message whose body contains a byte array, retrieves the message, and tests the retrieved message body to see if it is an array of bytes.
Option Explicit
Dim qinfo As New MSMQQueueInfo
Dim qSend As MSMQQueue
Dim qReceive As MSMQQueue
Dim mSend As New MSMQMessage
Dim mReceive As MSMQMessage
Private Sub Form_Click()
'*************************************************************
' Create a destination queue and open it with SEND access.
'*************************************************************
qinfo.PathName = ".\SendTest"
qinfo.Label = "Send Message Test"
On Error Resume Next 'Ignore if queue already exists.
qinfo.Create
On Error GoTo 0
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
'*************************************************************
' Send message with an array of bytes.
'*************************************************************
Dim aByte(5) As Byte
Dim Counter As Integer
'Populate the array
For Counter = LBound(aByte) To UBound(aByte)
aByte(Counter) = CByte(Counter)
Next
mSend.Label = "Array of Bytes Message"
mSend.Body = aByte
mSend.Send qSend
qSend.Close
'*************************************************************
' Open the destination queue with RECEIVE access, and
' retrieve the message. The retrieved message body is tested
' to verify it is an array of bytes.
'*************************************************************
Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set mReceive = qReceive.Receive
qReceive.Close
If TypeName(mReceive.Body) = "Byte()" Then
MsgBox "The retrieved message body is an array of bytes."
Else
MsgBox "The retrieved message body is not an array of bytes."
End If
End Sub