The queue identifier (PROPID_Q_INSTANCE) is a GUID that identifies the queue. It is created by MSMQ when the queue is created.
When retrieving the queue identifier, you must allocate a buffer of type CLSID for the returned GUID.
 To retrieve PROPID_Q_INSTANCE
To retrieve PROPID_Q_INSTANCE// 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 instance GUID.
 CLSID InstanceBuffer;
aQueuePropId[PropIdCount] = PROPID_Q_INSTANCE;   //Property ID
aQueuePropVar[PropIdCount].vt = VT_CLSID;        //Type indicator
aQueuePropVar[PropIdCount].puuid = &InstanceBuffer;
PropIdCount++;
QueueProps.cProp = PropIdCount;           // Number of properties
QueueProps.aPropID = aQueuePropId;        // Ids of properties
QueueProps.aPropVar = aQueuePropVar;      // Values of properties
QueueProps.aStatus = aQueueStatus;        // Error reports
hr = MQPathNameToFormatName(L"machinename\\queuename",
                              szFormatNameBuffer,
                                  &dwFormatNameBufferLength);
if (FAILED(hr))
   {
   fprintf(stderr, "Failed in MQPathNameToFormatName, error = 0x%x\n",hr);
   return -1;
   }hr = MQGetQueueProperties(szFormatNameBuffer, &QueueProps);
if (FAILED(hr))
   {
   fprintf(stderr, "Failed in MQGetQueueProperties, error = 0x%x\n",hr);
   return -1;
   }
 UCHAR *pszInstanceGUID;
if (UuidToString(aQueuePropVar[0].puuid, &pszInstanceGUID)== RPC_S_OK)
{
  printf("The identifier for this queue is: ");
  printf("%s.\n", pszInstanceGUID);
  RpcStringFree(&pszInstanceGUID);
}
The following example retrieves the PROPID_Q_INSTANCE 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 instance GUID.
  CLSID InstanceBuffer;
  
  ///////////////////////////////////
  // Specify PROPID_Q_INSTANCE.
  ///////////////////////////////////
  
  aQueuePropId[PropIdCount] = PROPID_Q_INSTANCE;    // Property ID
  aQueuePropVar[PropIdCount].vt = VT_CLSID;         // Type indicator
  aQueuePropVar[PropIdCount].puuid = &InstanceBuffer;
  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 identifier of the queue.
  //////////////////////////////////////////////
  
  UCHAR *pszInstanceGUID;
  if (UuidToString(aQueuePropVar[0].puuid, &pszInstanceGUID)== RPC_S_OK)
  {
    printf("The identifier for this queue is: ");
    printf("%s.\n", pszInstanceGUID);
    RpcStringFree(&pszInstanceGUID);
  }
  
  return 0;
  
}