C-C++ Code Example: Retrieving PROPID_Q_INSTANCE
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-define function that retrieves the PROPID_Q_INSTANCE property of an existing queue returns the identifier of the queue to the caller.
To retrieve PROPID_Q_INSTANCE
Define an MQQUEUEPROPS structure.
Validate the input parameters provided by the caller.
Specify PROPID_Q_INSTANCE
Set the puuid field of the applicable element of the property value array to point to the GUID buffer supplied by the caller.
Initialize the MQQUEUEPROPS structure.
Call MQGetQueueProperties to retrieve the identifier of the queue and place it in the application-created GUID buffer. If the call fails, the returned error code is returned to the caller.
Code Example
The following code example can be run on all versions of Message Queuing.
HRESULT GetQueueInstanceProp(
LPCWSTR wszQueueFormatName,
CLSID *pIDValue
)
{
// 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 || pIDValue == NULL)
{
return MQ_ERROR_INVALID_PARAMETER;
}
// Specify the PROPID_Q_INSTANCE property.
aQueuePropId[cPropId] = PROPID_Q_INSTANCE; // Property ID
aQueuePropVar[cPropId].vt = VT_CLSID; // Type indicator
aQueuePropVar[cPropId].puuid = pIDValue;
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);
return hr;
}