Sample code
The following sample code illustrates how to set the correct
BodyStream property and the correct
BodyType property for a
Message instance before you send
the message to a Message Queuing queue that a Message Queuing receive function
is monitoring.
Microsoft provides programming examples for illustration only,
without warranty either expressed or implied. This includes, but is not limited
to, the implied warranties of merchantability or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language that is being demonstrated and with the tools that are used to create
and to debug procedures. Microsoft support engineers can help explain the
functionality of a particular procedure, but they will not modify these
examples to provide added functionality or construct procedures to meet your
specific requirements.
using System;
using System.Messaging;
using System.Runtime.InteropServices;
class Class1
{
[STAThread]
static void Main(string[] args)
{
byte[] bytArray = new byte[] {72, 0, 101, 0, 108, 0, 108, 0, 111, 0}; //Hello
MessageQueue mq = new MessageQueue("FormatName:DIRECT=OS:.\\private$\\TestQ");
System.Messaging.Message msg = new System.Messaging.Message();
msg.BodyStream.Write(bytArray,0, bytArray.Length);
msg.BodyType = (int) (VarEnum.VT_ARRAY | VarEnum.VT_UI1);
msg.AppSpecific = -1;
mq.Send(msg, MessageQueueTransactionType.Single);
}
}