Example: Using Data Queues APIs

The following example illustrates using Data Queues APIs.

// Sample Data Queues application
 
#ifdef UNICODE
   #define _UNICODE
#endif
#include <windows.h>
 
// Include the necessary DQ Classes
#include <stdlib.h>
#include <iostream.h>
#include "cwbdq.h"
 
/**********************************************************************/
 
void main()
{
 
   cwbDQ_Attr queueAttributes;
   cwbDQ_QueueHandle queueHandle;
   cwbDQ_Data queueData;
 
   // Create an attribute object
   if ( (queueAttributes = cwbDQ_CreateAttr()) == 0 )
      return;
 
   // Set the maximum record length to 100
   if ( cwbDQ_SetMaxRecLen(queueAttributes,
                           100) != 0 )
      return;
 
   // Set the order to First-In-First-Out
   if (cwbDQ_SetOrder(queueAttributes, CWBDQ_SEQ_FIFO) != 0 )
      return;
 
   // Create the data queue DTAQ in library QGPL on system SYS1
   if ( cwbDQ_Create(_TEXT("DTAQ"),
                     _TEXT("QGPL"),
                     _TEXT("SYSNAMEXXX"),
                     queueAttributes,
                     NULL) != 0 )
      return;
 
   // Delete the attributes
   if ( cwbDQ_DeleteAttr( queueAttributes ) != 0 )
      return;
 
   // Open the data queue
   if ( cwbDQ_Open(_TEXT("DTAQ"),
                   _TEXT("QGPL"),
                   _TEXT("SYSNAMEXXX"),
                   &queueHandle,
                   NULL) != 0 )
 
       return;
 
   // Create a data object
   if ( (queueData = cwbDQ_CreateData()) == 0 )
      return;
 
   // Set the data length and the data
   if ( cwbDQ_SetData(queueData, (unsigned char*)"Test Data!", 10) != 0 )
      return;
 
   // Write the data to the data queue
   if ( cwbDQ_Write(queueHandle, queueData, CWB_TRUE, NULL) != 0 )
      return;
 
   // Delete the data object
   if ( cwbDQ_DeleteData(queueData) != 0 )
      return;
 
   // Close the data queue
   if ( cwbDQ_Close(queueHandle) != 0 )
      return;
 
}