Partager via


C-C++ Code Example: Retrieving PROPID_Q_CREATE_TIME

 

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_CREATE_TIME property of an existing queue and returns the date and time to the caller.

Note

The value returned by Message Queuing is the number of seconds that have elapsed since midnight (00:00:00), January 1, 1970 (Coordinated Universal Time) according to the system clock. Applications can call several related C run-time functions, such as ctime(), to manipulate this returned value. When using these run-time functions, include the time.h header file in your source code.

This function can use information stored on the local computer to return the date and time when a local private queue was created, but it must retrieve information stored in the directory service to return the date and time when a local or remote public queue was created. This function cannot be used to obtain the date and time when a remote private queue was created.

A direct format name can be passed to this function only for a local private queue.

To retrieve PROPID_Q_CREATE_TIMEf81f8731-df95-482c-ae71-20da119f03bf

  1. Define the MQQUEUEPROPS structure.

  2. Validate the input parameters provided by the caller.

  3. Specify PROPID_Q_CREATE_TIME.

  4. Initialize the MQQUEUEPROPS structure.

  5. Call MQGetQueueProperties to retrieve the date and time when the queue was created. If the call fails, the returned error code is returned to the caller.

  6. Pass the date and time when the queue was created to the caller on return.

Code Example

The following code example can be run on all versions of Message Queuing.

HRESULT GetQueueCreateTimeProp(  
                               LPCWSTR wszQueueFormatName,   
                               LONG *plValue  
                               )  
{  
  
  // Define the maximum number of queue properties.  
  const int NUMBEROFPROPERTIES = 1;  
  
  // Define a queue property structure.  
  DWORD cPropId=0;  
  MQQUEUEPROPS   QueueProps;  
  QUEUEPROPID    aQueuePropId[NUMBEROFPROPERTIES];  
  MQPROPVARIANT  aQueuePropVar[NUMBEROFPROPERTIES];  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT hr = MQ_OK;  
  
  // Validate the input parameters .  
  if (wszQueueFormatName == NULL || plValue == NULL)  
  {  
    return MQ_ERROR_INVALID_PARAMETER;  
  }  
  
  // Specify the PROPID_Q_CREATE_TIME property.  
  aQueuePropId[cPropId] = PROPID_Q_CREATE_TIME;   // Property ID  
  aQueuePropVar[cPropId].vt = VT_NULL;            // Type indicator  
  cPropId++;  
  
  // Initialize the MQQUEUEPROPS structure.  
  QueueProps.cProp = cPropId;  
  QueueProps.aPropID = aQueuePropId;  
  QueueProps.aPropVar = aQueuePropVar;  
  QueueProps.aStatus = aQueuePropStatus;  
  
  // Get the queue properties.  
  hr = MQGetQueueProperties(wszQueueFormatName, &QueueProps);  
  if (FAILED(hr))  
  {  
    return hr;  
  }  
  
  // Set the *plValue parameter to pass the date and time when the   
  // queue was created on return.  
  *plValue = aQueuePropVar[0].lVal;  
  return hr;  
}