07.11.2014 Views

Message Queuing Service Support in Windows CE - Trimar ...

Message Queuing Service Support in Windows CE - Trimar ...

Message Queuing Service Support in Windows CE - Trimar ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

You can compile and run the code on a W<strong>in</strong>dows NT, W<strong>in</strong>dows 9x, or W<strong>in</strong>dows<br />

2000–based platform us<strong>in</strong>g the Microsoft Visual C++ development system or<br />

another C++ compiler with the W<strong>in</strong>32 Platform Software Development Kit (SDK).<br />

You must <strong>in</strong>stall and configure the MSMQ service before runn<strong>in</strong>g the sample<br />

application.<br />

Us<strong>in</strong>g the Sample Application<br />

The follow<strong>in</strong>g illustration shows the sample application <strong>in</strong>terface.<br />

Follow<strong>in</strong>g are details on how to use the sample application.<br />

1. Click Create to create the queue shown <strong>in</strong> the Mach<strong>in</strong>e\Queue edit field.<br />

2. Click Send to send the message <strong>in</strong> the Send Text edit field to the queue shown<br />

<strong>in</strong> the Mach<strong>in</strong>e\Queue edit field.<br />

After each operation, the return value from the message queue API will be<br />

displayed <strong>in</strong> the Return Code edit field.<br />

1. Click Receive to receive a message synchronously from the queue shown <strong>in</strong> the<br />

Mach<strong>in</strong>e\Queue edit field. The call will time out if there are no messages <strong>in</strong> the<br />

queue. If a message is received, it will be displayed <strong>in</strong> the multil<strong>in</strong>e edit field at<br />

the bottom of the dialog box.<br />

2. To receive messages asynchronously with a thread/event mechanism from the<br />

queue shown <strong>in</strong> the Mach<strong>in</strong>e\Queue edit field, select the Async Receive with<br />

Thread/Event radio button and click Start Async Receive. When you click Send<br />

the message will be automatically dequeued and displayed <strong>in</strong> the multil<strong>in</strong>e edit<br />

field at the bottom of the dialog box.<br />

3. To receive a message asynchronously with a callback, repeat step 5 after<br />

select<strong>in</strong>g the Asynch Receive with Callback radio button.<br />

You also can start two copies of the application and send messages between them.<br />

Code Examples<br />

Follow<strong>in</strong>g are code examples detail<strong>in</strong>g the use of the CMQWrap class to create a<br />

queue, send a message, receive a message synchronously, and receive a message<br />

asynchronously with callback.<br />

To create a queue<br />

The follow<strong>in</strong>g code example shows how to create a queue us<strong>in</strong>g the CMQWrap<br />

class.<br />

CMQWrap q;<br />

q.Create(MQ_SEND_AC<strong>CE</strong>SS, L".\\private$\\myqueue", L"Created by MSMQTest");<br />

The CMQWrap::Create function creates and opens a queue <strong>in</strong> two steps. First, it<br />

uses the MQCreateQueue API to create a data structure conta<strong>in</strong><strong>in</strong>g two properties<br />

11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!