To request response messages, the sending application must supply a response queue for the returned messages. Response messages are application-defined, and generated by the application reading the message.
////////////////////////////// // Open the destination queue // with send access. ////////////////////////////// QUEUEHANDLE hQueue; hr = MQOpenQueue(szFormatName, MQ_SEND_ACCESS, 0, &hQueue); if (FAILED(hr)) { fprintf(stderr, "Failed in MQOpenQueue, error = 0x%x\n", hr); return -1; }
///////////////////////////////////////// // Set the PROPID_M_RESPONSE_QUEUE property. ///////////////////////////////////////// aPropId[PropIdCount] = PROPID_M_RESPONSE_QUEUE; //PropId aVariant[PropIdCount].vt = VT_LPWSTR; //Type aVariant[PropIdCount].pwszVal = szwRespFormatName; //An already obtained format name of the response queue. PropIdCount++;
//////////////////////////////// // Set the MQMSGPROPS structure. //////////////////////////////// MsgProps.cProp = PropIdCount; //Number of properties. MsgProps.aPropID = aPropId; //Ids of properties. MsgProps.aPropVar = aVariant; //Values of properties. MsgProps.aStatus = NULL; //No Error report.
///////////////// // Send message. ///////////////// hr = MQSendMessage( hQueue, // handle to the Queue. &MsgProps, // Message properties to be sent. MQ_NO_TRANSACTION // No transaction );
The following example sends a message requesting full receive acknowledgments.
MQMSGPROPS MsgProps; PROPVARIANT aVariant[10]; MSGPROPID aPropId[10]; DWORD PropIdCount = 0; HRESULT hr; ////////////////////////////// // Open the destination queue // with send access. ////////////////////////////// QUEUEHANDLE hQueue; hr = MQOpenQueue(szFormatName, MQ_SEND_ACCESS, 0, &hQueue); if (FAILED(hr)) { fprintf(stderr, "Failed in MQOpenQueue, error = 0x%x\n", hr); return -1; } QUEUEHANDLE hQueue; ///////////////////////////////////////// // Set the PROPID_M_RESP_QUEUE property. ///////////////////////////////////////// aPropId[PropIdCount] = PROPID_M_RESP_QUEUE; //PropId aVariant[PropIdCount].vt = VT_LPWSTR; //Type aVariant[PropIdCount].pwszVal = szwRespFormatName; //An already obtained format name of the response queue. PropIdCount++; //////////////////////////////////////// // Set other message properties, such // as PROPID_M_BODY and PROPID_M_LABEL. /////////////////////////////////////// //////////////////////////////// // Set the MQMSGPROPS structure. //////////////////////////////// MsgProps.cProp = PropIdCount; //Number of properties. MsgProps.aPropID = aPropId; //Ids of properties. MsgProps.aPropVar = aVariant; //Values of properties. MsgProps.aStatus = NULL; //No Error report. ///////////////// // Send message. ///////////////// hr = MQSendMessage( hQueue, // handle to the Queue. &MsgProps, // Message properties to be sent. MQ_NO_TRANSACTION // No transaction ); if (FAILED(hr)) { // // Handle error condition // }