Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
When opening a queue to read messages, the receiving application must specify how the messages are read from the queue and who else can access the queue when it is open.
The queue's access mode can be set to MQ_PEEK_ACCESS or MQ_RECEIVE_ACCESS. Use MQ_PEEK_ACCESS when you want to peek at messages without removing them. Use MQ_RECEIVE_ACCESS when you want to peek or retrieve the messages in the queue.
The queue's share mode can be set to MQ_DENY_NONE or MQ_DENY_SHARE_RECEIVE. When peeking at the messages in the queue, MQ_DENY_NONE must be specified. When retrieving messages, either setting can be used.
Both these modes are set when calling MSMQQueueInfo.Open.
Note: |
---|
Before opening a queue, Message Queuing verifies that the access mode requested by the application does not conflict with the access rights of the queue. If MQ_ERROR_ACCESS_DENIED is returned to the Open call, the queue's access control is blocking the application from opening the queue. |
-
Declare a MSMQQueueInfoand MSMQQueueobject.
-
Obtain a MSMQQueueInfoobject.
The C++ COM code example tries to create a new MSMQQueueInfoobject, ignoring any errors if a queue with the same pathname already exists. QueueInfoobjects for public queues can also be obtained from doing a query on the directory service.
-
Call MSMQQueueInfo.Opento open the queue with receive or peek access.
The following examples open the queue with receive access and deny none share mode.
-
(Optional) Add code for retrieving messages from the queue.
-
Call MSMQQueue.Closeto close the queue.
For a code example using C++ COM, see C++ COM Code Example: Opening a Queue to Read Messages.