The MQOpenQueue function opens a queue for sending messages to the queue or for reading its messages.
HRESULT APIENTRY MQOpenQueue(
LPCWSTR lpwcsFormatName,
DWORD dwAccess,
DWORD dwShareMode,
LPQUEUEHANDLE phQueue
);
Specify one of the following access modes:
See dwShareMode for limiting who can receive the messages.
If the format name of the queue is unknown, see Format Name to find ways to obtain a new format name.
Direct format names can only be used to open a queue for sending messages. A direct format name instructs MSMQ not to use Active Directory (for public queues) or the local computer (for private queues) to get routing information. When a direct format name is used to send messages, all routing information is derived from the provided format name and MSMQ sends the messages to the queue in a single hop.
Setting dwShareMode to MQ_DENY_RECEIVE_SHARE indicates that until the calling application calls MQCloseQueue, no other MSMQ applications can open a queue with receive access.
When opening a queue on a remote computer, MSMQ does not check for the existence of the queue when dwAccess is set to MQ_SEND_ACCESS. In addition, if dwAccess is set to MQ_RECEIVE_ACCESS, the computer opening the queue must support the same protocol as the remote computer where the queue is located.
Journal queues and dead letter queues can only be opened with dwAccess set to MQ_PEEK_ACCESS or MQ_RECEIVE_ACCESS. You cannot send messages to a journal queue.
Foreign queues cannot be opened using a direct format name. MSMQ needs the routing information stored in Active Directory to find an MSMQ Connector Sever for the foreign queue.
If the calling application does not have sufficient access rights to a queue, the following two things can happen:
To change the access rights of the queue, call MQSetQueueSecurity. The following table lists the access right needed to open the queue in peek, send, or receive access mode.
Queue Access Mode | Queue Access Right |
---|---|
MQ_PEEK_MESSAGE | MQSEC_PEEK_MESSAGE |
MQ_SEND_MESSAGE | MQSEC_WRITE_MESSAGE |
MQ_RECEIVE_MESSAGE | MQSEC_RECEIVE_MESSAGE |
There is no provision to change the access mode of the queue when it is open. Either close and open the queue with the desired access mode, or open a second instance of the queue.
For Windows NT, a queue handle is always inherited by a child process. If a child process is created by the process that opened the queue, the queue handle is inherited by the child process.
A queue handle is not inherited by a child process.
For examples of using MQOpenQueue, see:
Windows NT: Requires version 4.0 SP3 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in mq.h.
Import Library: Use mqrt.lib.
Unicode: Defined only as Unicode.
MQCloseQueue, MQReceiveMessage, MQSetQueueSecurity