请教msmq的使用
我在windows2000 server上装了msmq,然后将msdn上的建立主队列的例子程序拷下来运行,但总是失败,请教各位是什么原因。
程序如下:
#include <windows.h>
#include <stdio.h>
#include <mq.h> // Message Queuing header file
int main(int arg, char *argv[])
{
////////////////////////////////////////////////////////////
// Define the required structures.
////////////////////////////////////////////////////////////
#define NUMBEROFPROPERTIES 2 // Number of queue properties
DWORD cPropId = 0; // Define the property counter.
//Define the MQQUEUPROPS structure.
MQQUEUEPROPS QueueProps;
MQPROPVARIANT aQueuePropVar[NUMBEROFPROPERTIES];
QUEUEPROPID aQueuePropId[NUMBEROFPROPERTIES];
HRESULT aQueueStatus[NUMBEROFPROPERTIES];
HRESULT hr; // Define results.
PSECURITY_DESCRIPTOR pSecurityDescriptor=NULL; // Security descriptor
// Queue pathname
LPWSTR wszPathName = L".\\TestQueue";
// Queue label
LPWSTR wszQueueLabel = L"Test Queue";
// Format name buffer for queue
DWORD dwFormatNameBufferLength = 256; // Length of format name buffer
WCHAR wszFormatNameBuffer[256]; // Format name buffer
/////////////////////////////////////////////////////////////////
// Specify PROPID_Q_PATHNAME.
/////////////////////////////////////////////////////////////////
aQueuePropId[cPropId] = PROPID_Q_PATHNAME; // Property ID
aQueuePropVar[cPropId].vt = VT_LPWSTR; // Type indicator
aQueuePropVar[cPropId].pwszVal = wszPathName; // Pathname of queue
cPropId++;
/////////////////////////////////////////////////////////////////
// Add additional queue properties here. When adding properties,
// increment NUMBEROFPROPERTIES to reflect total number of
// properties.
/////////////////////////////////////////////////////////////////
aQueuePropId[cPropId] = PROPID_Q_LABEL; // Property ID
aQueuePropVar[cPropId].vt = VT_LPWSTR; // Type indicator
aQueuePropVar[cPropId].pwszVal = wszQueueLabel; // Label of queue
cPropId++;
/////////////////////////////////////////////////////////////////
// Initialize the MQQUEUEPROPS structure.
/////////////////////////////////////////////////////////////////
QueueProps.cProp = cPropId; // Number of properties
QueueProps.aPropID = aQueuePropId; // Ids of properties
QueueProps.aPropVar = aQueuePropVar; // Values of properties
QueueProps.aStatus = aQueueStatus; // Error reports
/////////////////////////////////////////////////////////////////
//Create Queue.
/////////////////////////////////////////////////////////////////
hr = MQCreateQueue(pSecurityDescriptor, // Security descriptor
&QueueProps, // Queue properties
wszFormatNameBuffer, // OUT: Format name of queue
&dwFormatNameBufferLength); // OUT: Format name length
if (FAILED(hr))
{
switch( hr )
{
case MQ_ERROR_QUEUE_EXISTS:
fprintf(stderr, "The queue already exists!\n");
break;
default:
fprintf(stderr, "Failed creating queue, error = 0x%x\n",hr);
break;
}
return -1;
}
puts ("The queue is created!");
return 0;
}