Platform SDK: Message Queuing |
The following example retrieves the PROPID_Q_BASEPRIORITY property for a known queue and then prints the returned value to the screen.
#include <windows.h> #include <stdio.h> #include <mq.h> // MSMQ header file int main(int arg, char *argv[]) { //////////////////////////////////////////////////////////////////// // Define structures. //////////////////////////////////////////////////////////////////// #define NUMBEROFPROPERTIES 1 DWORD cPropId = 0; MQQUEUEPROPS qprops; PROPVARIANT aQueuePropVar[NUMBEROFPROPERTIES]; QUEUEPROPID aQueuePropId[NUMBEROFPROPERTIES]; HRESULT aQueueStatus[NUMBEROFPROPERTIES]; HRESULT hr; DWORD dwFormatNameBufferLength = 256; WCHAR wszFormatNameBuffer[256]; //////////////////////////////////////////////////////////////////// // Specify PROPID_Q_BASEPRIORITY. //////////////////////////////////////////////////////////////////// aQueuePropId[cPropId] = PROPID_Q_BASEPRIORITY; // Property ID aQueuePropVar[cPropId].vt = VT_I2; // Type indicator cPropId++; //////////////////////////////////////////////////////////////////// // Add additional queue properties here. When adding // properties, increment cProp to // reflect total number of properties. //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Initialize the MQQUEUEPROPS structure. //////////////////////////////////////////////////////////////////// qprops.cProp = cPropId; // Number of properties qprops.aPropID = aQueuePropId; // Ids of properties qprops.aPropVar = aQueuePropVar; // Values of properties qprops.aStatus = aQueueStatus; // Error reports //////////////////////////////////////////////////////////////////// //Get format name of queue. //////////////////////////////////////////////////////////////////// hr = MQPathNameToFormatName(L".\\testqueue", wszFormatNameBuffer, &dwFormatNameBufferLength); if (FAILED(hr)) { fprintf(stderr, "Failed in MQPathNameToFormatName, error = 0x%x\n",hr); return -1; } //////////////////////////////////////////////////////////////////// // Get queue property. //////////////////////////////////////////////////////////////////// hr = MQGetQueueProperties(wszFormatNameBuffer, &qprops); if (FAILED(hr)) { fprintf(stderr, "Failed in MQGetQueueProperties, error = 0x%x\n",hr); return -1; } //////////////////////////////////////////////////////////////////// // Review returned value. This example prints // out the priority level of the queue. //////////////////////////////////////////////////////////////////// printf("PROPID_Q_BASEPRIORITY is set to "); printf("%d.\n", aQueuePropVar[0].iVal); return 0; }