Share via


C-C++ Code Example: Setting PROPID_Q_BASEPRIORITY

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

This example provides an application-defined function that sets the PROPID_Q_BASEPRIORITY property of an existing public queue based on a base priority level provided by the caller.

Setting this property changes how Message Queuing routes new messages sent to the queue. Setting this property has no effect on messages already in the queue.

To set PROPID_Q_BASEPRIORITY

  1. Validate the input parameters provided by the caller.

  2. Define the maximum number of queue properties to be specified and the queue property counter.

  3. Define the MQQUEUEPROPS structure.

  4. Specify PROPID_Q_BASEPRIORITY.

  5. Initialize the MQQUEUEPROPS structure.

  6. Call MQSetQueueProperties to set the base priority of the queue. If the call fails the returned error code is returned to the caller.

Code Example

The following code example can be run on all versions of Message Queuing.

HRESULT SetQueueBasePriorityProp(LPCWSTR wszQueueFormatName,   
                                 SHORT iValue)  
{  
  
  // Validate the input string.  
  if (wszQueueFormatName == NULL) return MQ_ERROR_INVALID_PARAMETER;  
  
  // Define the maximum number of queue properties and a property counter.  
  const int NUMBEROFPROPERTIES = 1;  
  DWORD cPropId=0;  
  
  // Define a queue property structure.  
  MQQUEUEPROPS   QueueProps;  
  QUEUEPROPID    aQueuePropId[NUMBEROFPROPERTIES];  
  MQPROPVARIANT  aQueuePropVar[NUMBEROFPROPERTIES];  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT hr = MQ_OK;  
  
  // Specify the PROPID_Q_BASEPRIORITY property.  
  aQueuePropId[cPropId] = PROPID_Q_BASEPRIORITY;   // Property ID  
  aQueuePropVar[cPropId].vt = VT_I2;               // Type indicator  
  aQueuePropVar[cPropId].iVal = iValue;            // Base priority  
  cPropId++;  
  
  // Initialize the MQQUEUEPROPS structure.  
  QueueProps.cProp = cPropId;  
  QueueProps.aPropID = aQueuePropId;  
  QueueProps.aPropVar = aQueuePropVar;  
  QueueProps.aStatus = aQueuePropStatus;  
  
  // Set the queue properties.  
  hr = MQSetQueueProperties(wszQueueFormatName, &QueueProps);  
  return hr;  
}