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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CMQWrap g_AsyncQ;<br />

void WINAPI AsyncCallback(CMQWrap* pThis, HRESULT hr, VARTYPE vt,<br />

DWORD dwSize)<br />

{<br />

// Do a receive <strong>in</strong> here as needed us<strong>in</strong>g the CMQWrap queue variable pThis<br />

}<br />

2. Start the callback mechanism. For example,<br />

g_AsyncQ.Open(MQ_RE<strong>CE</strong>IVE_AC<strong>CE</strong>SS, T2W(wszBuffer, szBuffer));<br />

g_AsyncQ.DoAsyncReceiveWithThread(AsyncCallback); // for us<strong>in</strong>g events<br />

g_AsyncQ.DoAsyncReceiveWithCallback(AsyncCallback); // for us<strong>in</strong>g callbacks<br />

The MQReceive<strong>Message</strong> can use two mechanisms to notify the caller<br />

asynchronously: a callback function and a W<strong>in</strong>32 event object. Both mechanisms<br />

work on the pr<strong>in</strong>ciple that the MQReceive<strong>Message</strong> call completes immediately and<br />

the caller is notified asynchronously when a message arrives <strong>in</strong> a queue. The<br />

CMQWrap class encapsulates both these mechanisms and passes the notification<br />

back to the caller us<strong>in</strong>g a CMQWrap-def<strong>in</strong>ed callback function.<br />

To receive messages asynchronously us<strong>in</strong>g W<strong>in</strong>32 events, the<br />

CMQWrap::DoAsyncReceiveWithThread function spawns a worker thread that<br />

calls MQReceive<strong>Message</strong> with a W<strong>in</strong>32 event object. The worker thread blocks on<br />

the event object after the MQReceive<strong>Message</strong> call. When a message arrives <strong>in</strong> the<br />

queue, the W<strong>in</strong>32 event object is signaled by MSMQ and the worker thread is<br />

activated and calls the caller’s callback function.<br />

Receiv<strong>in</strong>g messages us<strong>in</strong>g CMQWrap::DoAsyncReceiveWithCallback is less<br />

complex than us<strong>in</strong>g W<strong>in</strong>32 events. CMQWrap::DoAsyncReceiveWithCallback<br />

simply calls MQReceive<strong>Message</strong> with a private callback provided <strong>in</strong> the CMQWrap<br />

class. MSMQ calls this private callback function when a message arrives <strong>in</strong> the<br />

queue. The private callback function forwards the call to the callback function<br />

supplied by the caller. In both cases the caller is told that a message is <strong>in</strong> the queue<br />

and given details on the type and size of the message. The caller can dequeue the<br />

message <strong>in</strong> the callback at his or her discretion.<br />

For More Information<br />

For more <strong>in</strong>formation on MSMQ concepts, see Application <strong>Service</strong>s on the W<strong>in</strong>dows<br />

NT Server home site at http://www.microsoft.com/ntserver/ and the W<strong>in</strong>32 Platform<br />

Software Development Kit.<br />

For <strong>in</strong>formation on develop<strong>in</strong>g applications for W<strong>in</strong>dows <strong>CE</strong>, see the W<strong>in</strong>dows <strong>CE</strong><br />

Platform Software Development Kit.<br />

For papers and articles about W<strong>in</strong>dows <strong>CE</strong>, see the Microsoft W<strong>in</strong>dows <strong>CE</strong> Web<br />

site at http://www.microsoft.com/w<strong>in</strong>dowsce .<br />

1 3

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

Saved successfully!

Ooh no, something went wrong!