MQSendMessage
The MQSendMessage function sends a message to the queue corresponding to the handle hDestinationQueue.
HRESULT APIENTRY MQSendMessage(
QUEUEHANDLE hDestinationQueue,
MQMSGPROPS * pMessageProps,
ITransaction * pTransaction
);
Parameters
-
hDestinationQueue
-
[in] Handle to the queue where you want to send the message.
-
pMessageProps
-
[in] Pointer to an MQMSGPROPS structure describing the message to send.
-
pTransaction
-
[in] Must be a pointer to a transaction object, a constant, or NULL.
Transaction object can be obtained internally from MSMQ (by calling MQBeginTransaction), or externally from Microsoft® Distributed Transaction Coordinator (MS DTC).
Constants include:
-
MQ_NO_TRANSACTION
-
Specifies that the call is not part of a transaction.
-
MQ_MTS_TRANSACTION
-
Specifies that the current Microsoft Transaction Server (MTS) transaction is used to send the message.
-
MQ_SINGLE_MESSAGE
-
Sends a single message as a transaction. Messages sent as a single-message transaction must be sent to a transaction queue.
-
MQ_XA_TRANSACTION
-
Specifies that the call is part of an externally coordinated, XA-compliant transaction.
NULL indicates the message is not sent as part of a transaction.
Return Values
-
MQ_OK
-
Indicates success.
-
MQ_ERROR_ACCESS_DENIED
-
The queue was not opened with MQ_SEND_ACCESS rights.
-
MQ_ERROR_BAD_SECURITY_CONTEXT
-
The security context buffer (PROPID_M_SECURITY_CONTEXT) is corrupted.
-
MQ_ERROR_CORRUPTED_INTERNAL_CERTIFICATE
-
The internal security certificate provided by MSMQ is corrupted. Register the internal certificate again using the MSMQ Control Panel applet.
-
MQ_ERROR_CORRUPTED_PERSONAL_CERT_STORE
-
The Microsoft® Internet Explorer personal certificate store is corrupted.
-
MQ_ERROR_CORRUPTED_SECURITY_DATA
-
The operating system encountered an error when calling one of the cryptographic functions (CryptoAPI).
-
MQ_ERROR_COULD_NOT_GET_USER_SID
-
MQSendMessage could not retrieve the user identifier specified by PROPID_M_SENDERID.
-
MQ_ERROR_DTC_CONNECT
-
MSMQ was unable to connect to MS DTC.
-
MQ_ERROR_ILLEGAL_FORMATNAME
-
Format name specified in PROPID_M_ADMIN_QUEUE or PROPID_M_RESP_QUEUE is illegal.
-
MQ_ERROR_INVALID_CERTIFICATE
-
The external security certificate passed in PROPID_M_SENDER_CERT is not valid. The certificate is corrupted, or not placed in the Microsoft Internet Explorer personal certificate store.
-
MQ_ERROR_INVALID_HANDLE
-
The queue handle specified in hDestinationQueue is not valid.
-
MQ_ERROR_MESSAGE_STORAGE_FAILED
-
A recoverable message (PROPID_M_DELIVERY is set to MQMSG_DELIVERY_RECOVERABLE) could not be stored on the local computer.
-
MQ_ERROR_NO_INTERNAL_USER_CERT
-
The internal security certificate provided by MSMQ is not registered. Register the internal certificate using the MSMQ Control Panel.
-
MQ_ERROR_PROPERTY
-
One or more properties resulted in an error.
-
MQ_ERROR_SERVICE_NOT_AVAILABLE
-
Cannot connect to the Queue Manager.
-
MQ_ERROR_STALE_HANDLE
-
The specified queue handle was obtained in a previous session of the Queue Manager service. Close the queue and open it again to obtain a fresh handle.
-
MQ_ERROR_TRANSACTION_USAGE
-
Transaction error. Either the message is part of a transaction and its target queue is a non-transaction queue, or the message is not part of a transaction and the target queue is a transaction queue.
-
MQ_INFORMATION_PROPERTY
-
One or more of the properties resulted in a warning even though the function completed.
Remarks
All message properties can be attached to a message. Some are attached by MSMQ and others can be attached by the sending application. For a complete list of all the message properties, Sending Messages To a Queue.
The PROPID_M_BODY property is a CAUI1 structure that contains the message body. The caui1.cElems field of this structure represents the size of the message body.
The sending application can receive two types of messages in response to the messages it sends:
You can use the same queue for the response queue (PROPID_M_RESP_QUEUE) and administration queue (PROPID_M_ADMIN_QUEUE).
To save a copy of a message after it is successfully sent, set PROPID_M_JOURNAL to MQMSG_JOURNAL or MQMSG_JOURNAL | MQMSG_DEADLETTER and attach it to the message. This tells MSMQ to save a copy of message in the sending computer's machine journal after the message is successfully sent. For more information, see Journal Queues.
To save a copy of a message if it does not reach its destination, set PROPID_M_JOURNAL to MQMSG_DEADLETTER, or MQMSG_JOURNAL | MQMSG_DEADLETTER and attach it to the message. This tells MSMQ to save a copy of the message in the dead letter queue of the computer that could not deliver the message. This could be the sending machine, or any MSMQ server used to rout the message to its destination. For information on dead letter queues, see Dead Letter Queues.
When impersonating another user, MQGetSecurityContext must be called. Typically, MQGetSecurityContext is only needed when sending authenticated messages.
PROPID_M_RESP_QUEUE can be used to send the format name of a private queue to another application. This is typically done when the sending application wants to make a private queue available to other applications.
Sending Messages within a Transactions
If the send is part of a transaction (pTransaction is not set to MQ_NO_TRANSACTION or NULL), the hDestinationQueue parameter must refer to a transaction queue.
During a transaction, MSMQ performs the following tasks:
-
The message's priority property (PROPID_M_PRIORITY) is set to 0.
-
The message's delivery property (PROPID_M_DELIVERY) is set to MQMSG_DELIVERY_RECOVERABLE.
-
The time-to-be-received and time-to-reach-queue timers are set by the first message sent in the transaction. All subsequent messages use the first message's timer settings.
-
As part of a transaction, messages are not sent until the Commit time frame. For information on lTransaction::Commit, see the Platform SDK.
Requesting a Response
The sending application can pass PROPID_M_RESP_QUEUE to MQSendMessage to indicate that it expects a response from the receiving application. The messages returned to the response queue specified by this property are application-defined.
Examples
For examples of using MQSendMessage, see:
See Also
MQGetSecurityContext, MQMSGPROPS, MQSetQueueSecurity, PROPID_M_ACKNOWLEDGE, PROPID_M_ADMIN_QUEUE, PROPID_M_BODY, PROPID_M_BODY_SIZE, PROPID_M_CLASS, PROPID_M_DELIVERY, PROPID_M_JOURNAL, PROPID_M_MSGID, PROPID_M_PRIORITY, PROPID_M_RESP_QUEUE, PROPID_M_SENDERID, PROPID_M_SENTTIME, PROPID_M_TIME_TO_BE_RECEIVED, PROPID_M_TIME_TO_REACH_QUEUE
© 1997 by Microsoft Corporation. All rights reserved.