Expand Minimize

C/C++ Code Example: Retrieving PROPID_Q_INSTANCE

This example provides an application-define function that retrieves the PROPID_Q_INSTANCE property of an existing queue returns the identifier of the queue to the caller.

To retrieve PROPID_Q_INSTANCE

  1. Define an MQQUEUEPROPS structure.

  2. Validate the input parameters provided by the caller.

  3. Specify PROPID_Q_INSTANCE

  4. Set the puuid field of the applicable element of the property value array to point to the GUID buffer supplied by the caller.

  5. Initialize the MQQUEUEPROPS structure.

  6. Call MQGetQueueProperties to retrieve the identifier of the queue and place it in the application-created GUID buffer. 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 GetQueueInstanceProp(
                             LPCWSTR wszQueueFormatName, 
                             CLSID *pIDValue
                             )
{
  
  // 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 || pIDValue == NULL)
  {
    return MQ_ERROR_INVALID_PARAMETER;
  }
  
  
  // Specify the PROPID_Q_INSTANCE property.
  aQueuePropId[cPropId] = PROPID_Q_INSTANCE;   // Property ID
  aQueuePropVar[cPropId].vt = VT_CLSID;        // Type indicator
  aQueuePropVar[cPropId].puuid = pIDValue;
  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);
  
  return hr;
}
Show:
© 2014 Microsoft. All rights reserved.