Retrieving PROPID_Q_TYPE

The queue's type (PROPID_Q_TYPE) identifies the queue. Some queue types are defined by MSMQ. However, applications can define their own queue types so that they can later locate a set of queues by their type.

Note  For locating queues see MQLocateBegin.

When retrieving the queue type, you must allocate a buffer of type CLSID for the returned GUID.

To retrieve PROPID_Q_TYPE
  1. Define the structures needed to retrieve the properties. This includes the MQQUEUEPROPS structure and a buffer for the returned type GUID.
    // Define number of properties to be retrieved
    #define NumberOfProperties 1
    
    // Define property counter.
    DWORD PropIdCount = 0;
    
    // Define the MQQUEUPROPS structure.
    MQQUEUEPROPS QueueProps;
    PROPVARIANT aQueuePropVar[NumberOfProperties];
    QUEUEPROPID aQueuePropId[NumberOfProperties];
    HRESULT aQueueStatus[NumberOfProperties];
    
    // Define results.
    HRESULT hr;
    
    // Define format name buffer.
    DWORD dwFormatNameBufferLength = 256;
    WCHAR szFormatNameBuffer[256];
    
     // Define buffer for returned type GUID.
     CLSID TypeBuffer;
    
  2. Specify PROPID_Q_TYPE.
    aQueuePropId[PropIdCount] = PROPID_Q_TYPE;   //Property ID
    aQueuePropVar[PropIdCount].vt = VT_CLSID;        //Type indicator
    aQueuePropVar[PropIdCount].puuid = &TypeBuffer;
    PropIdCount++;
    
  3. Add any additional queue properties. When adding properties, increment the NumberOfProperties variable to reflect the number of properties added.
  4. Set the MQQUEUEPROPS structure.
    QueueProps.cProp = PropIdCount;           // Number of properties
    QueueProps.aPropID = aQueuePropId;        // Ids of properties
    QueueProps.aPropVar = aQueuePropVar;      // Values of properties
    QueueProps.aStatus = aQueueStatus;        // Error reports
    
  5. Obtain the format name of the queue. The example below uses MQPathNameToFormatName to obtain the format name of a known queue. Other functions that can be used are MQHandleToFormatName and MQInstanceToFormatName.
    hr = MQPathNameToFormatName(L"machinename\\queuename",
                                  szFormatNameBuffer,
                                      &dwFormatNameBufferLength);
    if (FAILED(hr))
       {
       fprintf(stderr, "Failed in MQPathNameToFormatName, error = 0x%x\n",hr);
       return -1;
       }
  6. Call MQGetQueueProperties.
    hr = MQGetQueueProperties(szFormatNameBuffer, &QueueProps);
    if (FAILED(hr))
       {
       fprintf(stderr, "Failed in MQGetQueueProperties, error = 0x%x\n",hr);
       return -1;
       }
     
  7. Examine the value of the returned property. In this example, the type of the queue is printed to the screen.
    UCHAR *pszTypeGUID;
    if (UuidToString(aQueuePropVar[0].puuid, &pszTypeGUID)== RPC_S_OK)
    {
      printf("The type for this queue is: ");
      printf("%s.\n", pszTypeGUID);
      RpcStringFree(&pszTypeGUID);
    }
     

Example Code

The following example retrieves the PROPID_Q_TYPE property for a known queue and then prints the returned value to the screen.

#include <windows.h>
#include <stdio.h>
#include <mq.h>                   // MSMQ header file
#include <rpc.h>                  // Defines UuidToString


int main(int arg, char *argv[])

{
  ////////////////////////////
  //  Define structures.
  ////////////////////////////
  
  // Define the number of properties
  #define NumberOfProperties 1
  
  // Define the property counter.
  DWORD PropIdCount = 0;
  
  //Define the MQQUEUPROPS structure.
  MQQUEUEPROPS QueueProps;
  PROPVARIANT aQueuePropVar[NumberOfProperties];
  QUEUEPROPID aQueuePropId[NumberOfProperties];
  HRESULT aQueueStatus[NumberOfProperties];
   
  //Define results.
  HRESULT hr;
  
  // Define format name buffer.
  DWORD dwFormatNameBufferLength = 256;
  WCHAR szFormatNameBuffer[256];
  
  // Define buffer for returned type GUID.
  CLSID TypeBuffer;
  
  ///////////////////////////////////
  // Specify PROPID_Q_TYPE.
  ///////////////////////////////////
  
  aQueuePropId[PropIdCount] = PROPID_Q_TYPE;    // Property ID
  aQueuePropVar[PropIdCount].vt = VT_CLSID;         // Type indicator
  aQueuePropVar[PropIdCount].puuid = &TypeBuffer;
  PropIdCount++;
  
  
  ///////////////////////////////////////////////////////
  // Add additional queue properties here. When adding 
  // properties, increment NumberOfProperties to 
  // reflect total number of properties.
  ///////////////////////////////////////////////////////
  
  
  ////////////////////////////////
  // Set the MQQUEUEPROPS structure.
  /////////////////////////////////
  QueueProps.cProp = PropIdCount;           // Number of properties
  QueueProps.aPropID = aQueuePropId;        // Ids of properties
  QueueProps.aPropVar = aQueuePropVar;      // Values of properties
  QueueProps.aStatus = aQueueStatus;        // Error reports
  
  
  ////////////////////////////
  //Get format name of queue.
  ////////////////////////////
  
  hr = MQPathNameToFormatName(L"machinename\\queuename",
                              szFormatNameBuffer,
                              &dwFormatNameBufferLength);
  if (FAILED(hr))
  {
    fprintf(stderr, "Failed in MQPathNameToFormatName, error = 0x%x\n",hr);
        return -1;
  }
  
  
  ////////////////////////////
  // Get queue property.
  ////////////////////////////
  
  hr = MQGetQueueProperties(szFormatNameBuffer, &QueueProps);
  if (FAILED(hr))
  {
    fprintf(stderr, "Failed in MQGetQueueProperties, error = 0x%x\n",hr);
        return -1;
  }
  
  
  ///////////////////////////////////////////////
  // Review returned value. This example prints 
  // out the type of the queue.
  //////////////////////////////////////////////
  
  UCHAR *pszTypeGUID;
  if (UuidToString(aQueuePropVar[0].puuid, &pszTypeGUID)== RPC_S_OK)
  {
    printf("The identifier for this queue is: ");
    printf("%s.\n", pszTypeGUID);
    RpcStringFree(&pszTypeGUID);
  }
  
  return 0;
  
}