C-C++ Code Example: Retrieving PROPID_Q_PATHNAME_DNS


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_PATHNAME_DNS property of an existing queue and returns the DNS path name to the caller.

The DNS path name of a queue is not stored like other queue properties. This path name is generated each time PROPID_Q_PATHNAME_DNS is retrieved. This function cannot be used to obtain the DNS path name of a remote private queue.


  1. Define the maximum number of queue properties to be specified and the queue property counter.

  2. Define the MQQUEUEPROPS structure.


  4. Initialize the MQQUEUEPROPS structure.

  5. Validate the input parameters provided by the caller.

  6. Call MQGetQueueProperties to generate the DNS path name of the queue. If the call fails the returned error code is returned to the caller.

  7. Pass a pointer to the string containing the retrieved DNS path name to the caller on return.


After your application no longer needs the DNS path name buffer, the caller must free the memory allocated for it using MQFreeMemory.

Code Example

The following code example requires MSMQ 2.0 or greater.

HRESULT GetQueuePathnameDNSProp(  
                                LPCWSTR wszQueueFormatName,   
                                LPWSTR *pwszValue  
  // Define the maximum number of queue properties and a property counter.  
  const int NUMBEROFPROPERTIES = 1;  
  DWORD cPropId=0;  
  // Define a queue property structure.  
  MQQUEUEPROPS   QueueProps;  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT hr = MQ_OK;  
  // Specify the PROPID_Q_PATHNAME_DNS property.  
  aQueuePropId[cPropId] = PROPID_Q_PATHNAME_DNS;    // Property ID  
  aQueuePropVar[cPropId].vt = VT_NULL;              // Type indicator  
  // Initialize the MQQUEUEPROPS structure.  
  QueueProps.cProp = cPropId;  
  QueueProps.aPropID = aQueuePropId;  
  QueueProps.aPropVar = aQueuePropVar;  
  QueueProps.aStatus = aQueuePropStatus;  
  // Validate the input string.  
  if (wszQueueFormatName == NULL)  
  // Get the queue properties.  
  hr = MQGetQueueProperties(wszQueueFormatName, &QueueProps);  
  if (FAILED(hr))  
    return hr;  
  // Set the *pwszValue parameter to the pointer to the string containing  
  // the DNS path name of the queue returned by MQGetQueueProperties.  
  *pwszValue = aQueuePropVar[0].pwszVal;  
  return hr;