Platform SDK: Message Queuing

C/C++ Code Example: Retrieving PROPID_Q_TYPE

The following example retrieves the PROPID_Q_TYPE property for a known queue and then prints the returned value to the screen. This example uses the RPC function UuidToString to display the type GUID of the queue. The library and header files for this function are rpcrt4.lib and rpc.h respectively.

#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 NUMBEROFPROPERTIES 1
  DWORD cPropId = 0;
  
  MQQUEUEPROPS qprops;
  PROPVARIANT aQueuePropVar[NUMBEROFPROPERTIES];
  QUEUEPROPID aQueuePropId[NUMBEROFPROPERTIES];
  HRESULT aQueueStatus[NUMBEROFPROPERTIES];
   
  HRESULT hr;
  DWORD dwFormatNameBufferLength = 256;
  WCHAR wszFormatNameBuffer[256];
  
  // Define buffer for returned type GUID.
  CLSID TypeBuffer;
  
  
  ////////////////////////////////////////////////////////////////////
  // Specify PROPID_Q_TYPE.
  ////////////////////////////////////////////////////////////////////
  
  aQueuePropId[cPropId] = PROPID_Q_TYPE;    // Property ID
  aQueuePropVar[cPropId].vt = VT_CLSID;         // Type indicator
  aQueuePropVar[cPropId].puuid = &TypeBuffer;
  cPropId++;
  
  
  ////////////////////////////////////////////////////////////////////
  // Add additional queue properties here. When adding 
  // properties, increment cProp to 
  // reflect total number of properties.
  ////////////////////////////////////////////////////////////////////
  
  
  ////////////////////////////////////////////////////////////////////
  // Initialize the MQQUEUEPROPS structure.
  ////////////////////////////////////////////////////////////////////
  qprops.cProp = cPropId;           // Number of properties
  qprops.aPropID = aQueuePropId;        // Ids of properties
  qprops.aPropVar = aQueuePropVar;      // Values of properties
  qprops.aStatus = aQueueStatus;        // Error reports
  
  
  ////////////////////////////////////////////////////////////////////
  //Get format name of queue.
  ////////////////////////////////////////////////////////////////////
  
  hr = MQPathNameToFormatName(L".\\testqueue",
                              wszFormatNameBuffer,
                              &dwFormatNameBufferLength);
  if (FAILED(hr))
  {
    fprintf(stderr, "Failed in MQPathNameToFormatName, error = 0x%x\n",hr);
        return -1;
  }
  
  
  ////////////////////////////////////////////////////////////////////
  // Get queue property.
  ////////////////////////////////////////////////////////////////////
  
  hr = MQGetQueueProperties(wszFormatNameBuffer, &qprops);
  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;
  
}