Jump to content

DosQueryQueue: Difference between revisions

From EDM2
Ak120 (talk | contribs)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
Queries the number of elements in a queue.
Queries the number of elements in a queue.


==Syntax==
==Syntax==
<PRE>
DosQueryQueue(hq, pcbEntries)
#define INCL_DOSQUEUES
#include <os2.h>


HQUEUE    hq;          /*  The handle of the queue to be queried. */
PULONG    pcbEntries;  /*  A pointer to the number of elements in the queue. */
APIRET    ulrc;        /*  Return Code. */
ulrc = DosQueryQueue(hq, pcbEntries);
</PRE>
==Parameters==
==Parameters==
; hq (HQUEUE) - input : The handle of the queue to be queried.  
;hq (HQUEUE) - input : The handle of the queue to be queried.
 
;pcbEntries (PULONG) - output : A pointer to the number of elements in the queue.
; pcbEntries (PULONG) - output : A pointer to the number of elements in the queue.  
==Return Code==
ulrc (APIRET) - returns
 
DosQueryQueue returns one of the following values:


* 0     NO_ERROR  
;ulrc (APIRET) - returns:Return Code.
* 337       ERROR_QUE_INVALID_HANDLE  
:DosQueryQueue returns one of the following values:
::0 NO_ERROR
::337 ERROR_QUE_INVALID_HANDLE


==Remarks==
==Remarks==
DosQueryQueue returns the number of elements that are currently in a queue. This function can be used by the server process and its threads, as well as by any client processes that have gained access to the queue by issuing DosOpenQueue.
DosQueryQueue returns the number of elements that are currently in a queue. This function can be used by the server process and its threads, as well as by any client processes that have gained access to the queue by issuing [[DosOpenQueue]].


If the server process closes the queue before this request is made, ERROR_QUE_INVALID_HANDLE is returned.  
If the server process closes the queue before this request is made, ERROR_QUE_INVALID_HANDLE is returned.


==Example Code==
==Example Code==
This example shows how to create, write, querie, and close a queue.
{{OS2API Example Queue2}}
<PRE>
#define INCL_DOSQUEUES  /* DOS Queue values */
#define INCL_DOSERRORS  /* DOS Error values */
#include <os2.h>
#include <stdio.h>
#include <string.h>
 
#define QUE_NAME "\\QUEUES\\PANDAWRITE\\LOCALQUEUE"
 
int main(VOID) {
 
  HQUEUE QueueHandle = NULLHANDLE;  /* Queue handle                  */
  CHAR  *DataBuffer = "";          /* Data to write to queue        */
  ULONG  ulNumElems  = 0L;          /* Number of elements on queue    */
  APIRET rc          = NO_ERROR;    /* Return code                    */
 
  rc = DosCreateQueue(&QueueHandle, /* Queue handle                  */
          QUE_LIFO |                /* Last In, First Out ordering    */
          QUE_CONVERT_ADDRESS,      /* Do 16-bit to 32-bit conversion */
          QUE_NAME);                /* Name of the queue              */
  if (rc!= NO_ERROR) {
      printf ("DosCreateQueue error: return code = %u\n", rc);
      return 1;
  }
 
  DataBuffer = "Element 1 of 2";
  rc = DosWriteQueue (QueueHandle, 100L, strlen(DataBuffer),
                      (PVOID)DataBuffer, 0L);
  if (rc!= NO_ERROR) {
      printf ("DosWriteQueue error: return code = %u\n", rc);
      return 1;
  }
 
  rc = DosQueryQueue (QueueHandle, &ulNumElems);
  if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
  } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }
 
  DataBuffer = "Element 2 of 2";
  rc = DosWriteQueue (QueueHandle, 200L, strlen(DataBuffer),
                      (PVOID)DataBuffer, 0L);
  if (rc!= NO_ERROR) {
      printf ("DosWriteQueue error: return code = %u\n", rc);
      return 1;
  }
 
  rc = DosQueryQueue (QueueHandle, &ulNumElems);
  if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
  } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }
  rc = DosPurgeQueue (QueueHandle);
  if (rc != NO_ERROR) {
      printf ("DosPurgeQueue error: return code = %u\n", rc);
      return 1;        }
 
  rc = DosQueryQueue (QueueHandle, &ulNumElems);
  if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
  } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }
 
  rc = DosCloseQueue(QueueHandle);      /* Close the queue */
  if (rc!= NO_ERROR) {
      printf ("DosCloseQueue error: return code = %u\n", rc);
      return 1;      }
 
  return NO_ERROR;
}


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosCloseQueue|DosCloseQueue]]
*[[DosCloseQueue]]
* [[OS2 API:CPI:DosCreateQueue|DosCreateQueue]]
*[[DosCreateQueue]]
* [[OS2 API:CPI:DosOpenQueue|DosOpenQueue]]
*[[DosOpenQueue]]
* [[OS2 API:CPI:DosPeekQueue|DosPeekQueue]]
*[[DosPeekQueue]]
* [[OS2 API:CPI:DosPurgeQueue|DosPurgeQueue]]
*[[DosPurgeQueue]]
* [[OS2 API:CPI:DosReadQueue|DosReadQueue]]
*[[DosReadQueue]]
* [[OS2 API:CPI:DosWriteQueue|DosWriteQueue]]
*[[DosWriteQueue]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 01:48, 13 December 2019

Queries the number of elements in a queue.

Syntax

DosQueryQueue(hq, pcbEntries)

Parameters

hq (HQUEUE) - input
The handle of the queue to be queried.
pcbEntries (PULONG) - output
A pointer to the number of elements in the queue.
ulrc (APIRET) - returns
Return Code.
DosQueryQueue returns one of the following values:
0 NO_ERROR
337 ERROR_QUE_INVALID_HANDLE

Remarks

DosQueryQueue returns the number of elements that are currently in a queue. This function can be used by the server process and its threads, as well as by any client processes that have gained access to the queue by issuing DosOpenQueue.

If the server process closes the queue before this request is made, ERROR_QUE_INVALID_HANDLE is returned.

Example Code

This example shows how to create, write, query, and close a queue.

#define INCL_DOSQUEUES   /* DOS Queue values */
#define INCL_DOSERRORS   /* DOS Error values */
#include <os2.h>
#include <stdio.h>
#include <string.h>

#define QUE_NAME "\\QUEUES\\PANDAWRITE\\LOCALQUEUE"

int main(VOID) {

   HQUEUE QueueHandle = NULLHANDLE;  /* Queue handle                   */
   CHAR   *DataBuffer = "";          /* Data to write to queue         */
   ULONG  ulNumElems  = 0L;          /* Number of elements on queue    */
   APIRET rc          = NO_ERROR;    /* Return code                    */

   rc = DosCreateQueue(&QueueHandle, /* Queue handle                   */
           QUE_LIFO |                /* Last In, First Out ordering    */
           QUE_CONVERT_ADDRESS,      /* Do 16-bit to 32-bit conversion */
           QUE_NAME);                /* Name of the queue              */
   if (rc!= NO_ERROR) {
      printf ("DosCreateQueue error: return code = %u\n", rc);
      return 1;
   }

   DataBuffer = "Element 1 of 2";
   rc = DosWriteQueue (QueueHandle, 100L, strlen(DataBuffer),
                       (PVOID)DataBuffer, 0L);
   if (rc!= NO_ERROR) {
      printf ("DosWriteQueue error: return code = %u\n", rc);
      return 1;
   }

   rc = DosQueryQueue (QueueHandle, &ulNumElems);
   if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
   } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }

   DataBuffer = "Element 2 of 2";
   rc = DosWriteQueue (QueueHandle, 200L, strlen(DataBuffer),
                       (PVOID)DataBuffer, 0L);
   if (rc!= NO_ERROR) {
      printf ("DosWriteQueue error: return code = %u\n", rc);
      return 1;
   }

   rc = DosQueryQueue (QueueHandle, &ulNumElems);
   if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
   } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }
   rc = DosPurgeQueue (QueueHandle);
   if (rc != NO_ERROR) {
      printf ("DosPurgeQueue error: return code = %u\n", rc);
      return 1;        }

   rc = DosQueryQueue (QueueHandle, &ulNumElems);
   if (rc != NO_ERROR) {
      printf ("DosQueryQueue error: return code = %u\n", rc);
      return 1;
   } else { printf ("DosQueryQueue: %u elements\n", ulNumElems); }

   rc = DosCloseQueue(QueueHandle);      /* Close the queue */
   if (rc!= NO_ERROR) {
      printf ("DosCloseQueue error: return code = %u\n", rc);
      return 1;       }

   return NO_ERROR;
}

Related Functions