다음을 통해 공유


C-C++ Code Example: Retrieving PROPID_Q_TYPE

 

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_TYPE property of an existing queue and returns the service type identifier (GUID) to the caller.

This function can return the service type GUID of a local private queue from information stored on the local computer, but must retrieve information stored in the directory service to return the service type GUID of a local or remote public queue. This function cannot be used to obtain the service type GUID of a remote private queue.

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

To retrieve PROPID_Q_TYPE

  1. Define the MQQUEUEPROPS structure.

  2. Validate the input parameters provided by the caller.

  3. Specify the PROPID_Q_TYPE property.

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

  5. Initialize the MQQUEUEPROPS structure.

  6. Call MQGetQueueProperties to retrieve the service type of the queue.

Code Example

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

HRESULT GetQueueTypeProp(  
                         LPCWSTR wszQueueFormatName,   
                         CLSID *pIDValue  
                         )  
{  
  
  // Specify an MQQUEUPROPS structure.  
  const int NUMBEROFPROPERTIES = 1;  
  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_TYPE property.  
  DWORD cPropId=0;  
  aQueuePropId[cPropId] = PROPID_Q_TYPE;       // 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;  
  
  // Call MQGetQueueProperties to retrieve the queue type identifier.  
  hr = MQGetQueueProperties(wszQueueFormatName, &QueueProps);  
  
  return hr;  
}