home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12192.ZIP / Q1.BAS next >
BASIC Source File  |  1990-02-02  |  2KB  |  78 lines

  1. '===== Q1.BAS =====
  2. REM $include: 'QUEUE.BI'
  3.  
  4. 'Functions to deal with data in shared memory (UTIL.BAS)
  5. DECLARE FUNCTION STRINGPOKE%(_
  6.               P1  AS ADDRESS,_
  7.               P2  AS STRING,_
  8.               P3  AS INTEGER)
  9. DECLARE FUNCTION STRINGPEEK%(_
  10.               P1  AS ADDRESS,_
  11.               P2  AS STRING,_
  12.               P3  AS INTEGER)
  13. DEFINT A-Z
  14. DIM info  AS ADDRESS
  15. DIM ep    AS STRING*1
  16.  
  17. 'Queue name
  18. QNAME$="\QUEUES\NANCYBA"+CHR$(0)
  19.  
  20. 'Shared memory
  21. DNAME$="\SHAREMEM\NANCYBA"+CHR$(0)
  22.  
  23. QUEUETYPE=0    'First In First Out
  24. CLS
  25.  
  26. 'Create Queue
  27. x=DosCreateQueue%(QHandle,QueueType,varseg(Qname$),sadd(Qname$))
  28. IF (x) THEN
  29.    Print "An error occurred.  The number is : ";x
  30.    stop
  31. ELSE
  32.    Print "The QUEUE ";qname$;" was CREATED"
  33.    PRINT "The HANDLE is : ";qhandle
  34. END IF
  35.  
  36. 'Create shared segment
  37. SIZE=1024
  38. ALLOCFLAGS=7
  39. x=DosAllocShrSeg%(size,varseg(dname$),sadd(dname$),selector)
  40. IF (x) THEN
  41.    Print "An error occurred.  The number is : ";x
  42.    stop
  43. ELSE
  44.    Print "The SEGMENT ";selector;" was CREATED"
  45. END IF
  46. PRINT "WAITING FOR INPUT TO THE QUEUES"
  47. DO
  48.    x=DosQueryQueue%(Qhandle,number)
  49. ' Loop until error or number > 0 :
  50. LOOP WHILE ( (x = 0)  and (number = 0) )
  51. IF (x) THEN
  52.    Print "An Error Occurred.  The number is : ";x
  53. ELSE
  54.    PRINT "There are ";number;" items in the QUEUE"
  55.    FOR i = 1 to number
  56.       x=DosReadQueue%(Qhandle,pr&,dlen,item&,0%,0%,_
  57.                       varseg(ep),varptr(ep),1&)
  58.       IF (x) THEN
  59.          Print "An error occurred.  The number is : ";x
  60.       ELSE
  61.          info.segment=item& \ (2^16)
  62.          info.offset=item& mod (2^16)
  63.          IF (stringpeek(info,st$,dlen)) THEN
  64.             PRINT "ERROR"
  65.          ELSE
  66.             Print "The item in the QUEUE was : ";st$
  67.          END IF
  68.       END IF
  69.    NEXT i
  70. END IF
  71. x=DosCloseQueue%(Qhandle)
  72. IF (x) THEN
  73.    Print "An error occurred.  The number is : ";x
  74. ELSE
  75.    Print "The QUEUE was closed."
  76. END IF
  77. END
  78.