C-C++ Code Example: Setting PROPID_Q_QUOTA


Updated: July 19, 2016

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_QUOTA property of an existing queue based on a given maximum queue size provided by the caller.

Setting this property for an existing queue changes the maximum size of the queue, however, it has no effect on messages already in the queue.

A direct format name can be passed to this function only for a local private queue.


  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_QUOTA.

  5. Initialize the MQQUEUEPROPS structure.

  6. Call MQSetQueueProperties to set the maximum size of the queue. If the call fails, the returned error code is returned to the caller.

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

HRESULT SetQueueQuotaProp(  
                          LPCWSTR wszQueueFormatName,  
                          int iValue  
  // Validate the input string.  
  if (wszQueueFormatName == NULL)  
  // 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;  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT hr = MQ_OK;  
  // Specify the PROPID_Q_QUOTA property.  
  aQueuePropId[cPropId] = PROPID_Q_QUOTA;         // Property ID  
  aQueuePropVar[cPropId].vt = VT_UI4;             // Type indicator  
  aQueuePropVar[cPropId].ulVal = iValue;          // Queue quota  
  // 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;  

Community Additions