Creating a New Queue

< BACK  NEXT >
[oR]

New queues can be created on a Windows CE device by calling the MQCreateQueue (Table 15.2) function and initializing a MQQUEUEPROPS structure with the following properties:

  • PROPID_Q_PATHNAME Pathname for the new queue

  • PROPID_Q_LABEL Label (or description) for the new queue

The data for both these properties is VT_LPWSTR. The pwszVal member for PROPID_Q_PATHNAME is a pointer to a string containing the pathname. In the following code example, the "." refers to the local Windows CE device, "PRIVATE$" specifies this is a private queue (remember, public queues are not supported), and "WinCEInQueue" is the name of the new queue.

 LPWSTR wszPathName = _T(".\\PRIVATE$\\WinCEInQueue"); aQueuePropId[0] = PROPID_Q_PATHNAME; aQueuePropVar[0].vt = VT_LPWSTR; aQueuePropVar[0].pwszVal = wszPathName; 

Table 15.2. MQCreateQueue Creates a new queue
MQCreateQueue
PSECURITY_DESCRIPTOR pSecurityDescriptor Not supported, pass as NULL.
MQQUEUEPROPS *pQueueProps Pointer to a MQQUEUEPROPS structure describing the queue to create.
LPWSTR lpwcsFormatName Pointer to a buffer to receive the format name of the new queue. This can be NULL.
LPDWORD lpdwFormatNameLength Length of the new buffer receiving the format name.
HRESULT Return Value MQ_OK for success, otherwise error code.

The PROPID_Q_LABEL can be used to provide a more descriptive name for the queue:

 LPWSTR wszQueueLabel =   _T("Message to be received by Windows CE Device"); aQueuePropId[1] = PROPID_Q_LABEL; aQueuePropVar[1].vt = VT_LPWSTR; aQueuePropVar[1].pwszVal = wszQueueLabel; 

The queue to be created is specified by a pathname, and the MQCreateQueue function will return the format name if required. The code in Listing 15.2 shows how to initialize properties and call MQCreateQueue to create a new queue on a Windows CE Device.

Listing 15.2 Creating a new queue
 void Listing15_2() {   DWORD cPropId = 0;   MQQUEUEPROPS QueueProps;   MQPROPVARIANT aQueuePropVar[2];   QUEUEPROPID aQueuePropId[2];   HRESULT aQueueStatus[2];   HRESULT hr   PSECURITY_DESCRIPTOR pSecurityDescriptor=NULL   // Queue pathname   LPWSTR wszPathName = _T(".\\PRIVATE$\\WinCEInQueue");   // Queue label   LPWSTR wszQueueLabel =     _T("Message to be received by Windows CE Device");   // Format name buffer for queue   DWORD dwFormatNameLength = 256   WCHAR wszFormatName[256];   aQueuePropId[cPropId] = PROPID_Q_PATHNAME;   aQueuePropVar[cPropId].vt = VT_LPWSTR;   aQueuePropVar[cPropId].pwszVal = wszPathName;   cPropId++;   aQueuePropId[cPropId] = PROPID_Q_LABEL;   aQueuePropVar[cPropId].vt = VT_LPWSTR;   aQueuePropVar[cPropId].pwszVal = wszQueueLabel;   cPropId++;   QueueProps.cProp = cPropId;   QueueProps.aPropID = aQueuePropId;   QueueProps.aPropVar = aQueuePropVar;   QueueProps.aStatus = aQueueStatus;   hr = MQCreateQueue(pSecurityDescriptor,       &QueueProps,       wszFormatName,       &dwFormatNameLength);   if(hr == MQ_OK)         cout   wszFormatName   _T(" created")   endl;   else if(hr == MQ_ERROR_ACCESS_DENIED )         cout   _T("Access Denied")   endl;   else if(hr == MQ_ERROR_ILLEGAL_PROPERTY_VALUE )         cout   _T("Illegal Property Value")   endl;   else if(hr == MQ_ERROR_ILLEGAL_QUEUE_PATHNAME )         cout   _T("Illegal pathname")   endl;   else if(hr == MQ_ERROR_ILLEGAL_SECURITY_DESCRIPTOR )         cout   _T("Illegal security descriptor")                endl;   else if(hr == MQ_ERROR_INSUFFICIENT_PROPERTIES )         cout   _T("Path name not specified")   endl;   else if(hr == MQ_ERROR_INVALID_OWNER )         cout   _T("Invalid owner")   endl;   else if(hr == MQ_ERROR_PROPERTY )         cout   _T("Error in property specification")                endl;   else if(hr == MQ_ERROR_PROPERTY_NOTALLOWED )         cout   _T("Property not allowed when creating queue")                endl;   else if(hr == MQ_ERROR_QUEUE_EXISTS )         cout   _T("Queue already exists")   endl;   else if(hr == MQ_ERROR_SERVICE_NOT_AVAILABLE )         cout   _T("Service not available")   endl;   else if(hr ==         MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL )         cout   _T("Format name buffer too small")           endl;   else if(hr == MQ_INFORMATION_PROPERTY )         cout          _T("Succeeded, but property returned warning")                endl; } 

Once the queue has been created, you will need to open the queue before messages can be sent or received from it. Queues can be deleted by calling the MQDeleteQueue function, and this is passed the format name of the queue to be deleted.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net