I am having trouble creating a message queue using MSMQ. I have little experience with C++ API. The following code compiles, but throws a "Failed to initialize error at runtime."
Code:
HRESULT MsgQueueCreate()
{
//Define the number of properties for each Msg Queue
const int NUMBER_OF_PROPERTIES = 3;
//First we have to define the MQQUEUEPROPS structure
MQQUEUEPROPS mq_props;
//and its properties
MQPROPVARIANT mq_prop_variant[NUMBER_OF_PROPERTIES];
QUEUEPROPID mq_prop_id[NUMBER_OF_PROPERTIES];
HRESULT mq_prop_hr[NUMBER_OF_PROPERTIES];
HRESULT result = MQ_OK;
DWORD prop_id = 0;
//Define a format name buffer and a buffer length
WCHAR formatBuffer[256];
DWORD formatBufferLength = sizeof(formatBuffer)/sizeof(formatBuffer[0]);
PSECURITY_DESCRIPTOR securityDescriptor;
//Next step is to fill in the values for the structure
mq_prop_id[prop_id] = PROPID_Q_PATHNAME;
mq_prop_variant[prop_id].vt = VT_NULL;
mq_prop_variant[prop_id].pwszVal = L".\\PRIVATE$\\MyPrivateQueue";
//increment the prop_id each time properties are added to the structure
prop_id++;
LPWSTR mq_label = L"Msg Queue";
mq_prop_id[prop_id] = PROPID_Q_LABEL;
mq_prop_variant[prop_id].vt = VT_LPWSTR;
mq_prop_variant[prop_id].pszVal = (char*)mq_label;
//increment the prop_id for the property count
prop_id++;
//initialize the MQQUEUEPROPS struct with the declared values
mq_props.cProp = prop_id;
mq_props.aPropID = mq_prop_id;
mq_props.aPropVar = mq_prop_variant;
mq_props.aStatus = mq_prop_hr;
securityDescriptor = NULL;
result = MQCreateQueue(securityDescriptor, &mq_props, formatBuffer, &formatBufferLength);
return result;
}