Retrieving PROPID_Q_MODIFY_TIME

The modify time of a queue is set by MSMQ whenever the queue's properties are set. This includes when MSMQ creates the queue, when the properties are changed by MQSetQueueProperties, or through MSMQ Explorer. Note that in this example, the C run-time function ctime() is used to display the returned value in a local date and time format.

Note  Details on the C run-time functions can be found in the Platform SDK. When using these functions, include time.h in your source code.

To retrieve PROPID_Q_MODIFY_TIME
  1. Define the structures needed to retrieve the properties. This includes the MQQUEUEPROPS structure.
    // 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];
    
  2. Specify PROPID_Q_MODIFY_TIME.
    aQueuePropId[PropIdCount] = PROPID_Q_MODIFY_TIME;  //Property ID
    aQueuePropVar[PropIdCount].vt = VT_I4;             //Type indicator
    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, ctime() is used to translate the returned value to a local date and time format.
    printf("The queue's properties were last modified on ");
    printf("%s.\n", ctime(&aQueuePropVar[0].lVal));
    

Example Code

The following example retrieves the PROPID_Q_MODIFY_TIME 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 <time.h>                     // Defines ctime()


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

{
  ///////////////////////////
  //  Define structures.
  ////////////////////////////

  // 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];
  
  
  ///////////////////////////////////
  // Specify PROPID_Q_MODIFY_TIME.
  ///////////////////////////////////
  
  aQueuePropId[PropIdCount] = PROPID_Q_MODIFY_TIME; // Property ID
  aQueuePropVar[PropIdCount].vt = VT_I4;            // Type indicator
  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"computername\\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
  // when the queue's properties were last modified.
  //////////////////////////////////////////////////
  
  printf("The queue's properties were last modified on ");
  printf("%s.\n", ctime(&aQueuePropVar[0].lVal));
  
  return 0;
 
}