次の方法で共有


C-C++ Code Example: Retrieving 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 retrieves the PROPID_Q_BASEPRIORITY property of an existing public queue and returns the base priority level of the queue to the caller.

This function must retrieve information stored in the directory service to return the base priority of an existing public queue.

To retrieve PROPID_Q_BASEPRIORITY

  1. Define an MQQUEUEPROPS structure.

  2. Validate the input parameters provided by the caller.

  3. Specify PROPID_Q_BASEPRIORITY.

  4. Initialize the MQQUEUEPROPS structure.

  5. Call MQGetQueueProperties to retrieve the base priority level of the queue. If the call fails, the returned error code is returned to the caller.

  6. Pass the retrieved base priority level to the caller on return.

Code Example

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

HRESULT GetQueueBasepriorityProp(  
                                 LPCWSTR wszQueueFormatName,   
                                 SHORT *piValue  
                                 )  
{  
  
  // Define the maximum number of queue properties.  
  const int NUMBEROFPROPERTIES = 1;  
  
  // Define a queue property structure.  
  DWORD cPropId=0;  
  MQQUEUEPROPS   QueueProps;  
  QUEUEPROPID    aQueuePropId[NUMBEROFPROPERTIES];  
  MQPROPVARIANT  aQueuePropVar[NUMBEROFPROPERTIES];  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT hr = MQ_OK;  
  
  // Validate the input parameters.  
  if (wszQueueFormatName == NULL || piValue == NULL)  
  {  
    return MQ_ERROR_INVALID_PARAMETER;  
  }  
  
  // Specify the PROPID_Q_BASEPROIORITY property.  
  aQueuePropId[cPropId] = PROPID_Q_BASEPRIORITY;  // Property ID  
  aQueuePropVar[cPropId].vt = VT_NULL;            // Type indicator  
  cPropId++;  
  
  // Initialize the MQQUEUEPROPS structure.  
  QueueProps.cProp = cPropId;  
  QueueProps.aPropID = aQueuePropId;  
  QueueProps.aPropVar = aQueuePropVar;  
  QueueProps.aStatus = aQueuePropStatus;  
  
  // Get the queue properties.  
  hr = MQGetQueueProperties(wszQueueFormatName, &QueueProps);  
  if (FAILED(hr))  
  {  
    return hr;  
  }  
  
  // Set the *piValue parameter to pass the base priority  
  // of the queue on return.  
  *piValue = aQueuePropVar[0].iVal;  
  return hr;  
}