home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / QUECALLS.E < prev    next >
Text File  |  1992-08-26  |  3KB  |  87 lines

  1. ; The following contains samples of dynalinking to the OS/2 queue
  2. ; function from EPM.  These are building blocks for you to use in
  3. ; your own code.
  4.  
  5. ; By Larry Margolis
  6.  
  7.    qhand = '  '
  8.    result=dynalink('QUECALLS',          -- Creating a queue
  9.                    'DOSCREATEQUEUE',
  10.                    selector(qhand)||offset(qhand)||
  11.                    atoi('0')||
  12.                    selector(queue_name)||offset(queue_name))
  13.    if result <> 0 then
  14.       sayerror 'Could not create queue: ' result
  15.       stop
  16.    endif
  17.  
  18.  
  19.    call dynalink('QUECALLS', 'DOSCLOSEQUEUE', qhand)  -- Closing a queue
  20.  
  21.  
  22.    result=dynalink('QUECALLS',     -- Writing to a queue
  23.                    'DOSWRITEQUEUE',
  24.                    qhand||
  25.                    atoi('0')||
  26.                    atoi(MAXBUFSIZE)||
  27.                    atoi(bufhndl)||atoi('0')||     /* address of buffer */
  28.                    atoi('0'))
  29.    if result <> 0 then
  30.       sayerror 'Could not write queue : ' result
  31.       call dynalink('QUECALLS', 'DOSCLOSEQUEUE', qhand)
  32.    endif
  33.  
  34. ; The following code opens a queue, reads from it, and inserts each
  35. ; element of the queue (assumed to be an EPM buffer as defined by the
  36. ; buffer() opcode) into the current file.
  37.    pid='  '
  38.    qhand = '  '
  39.    result=dynalink('QUECALLS',
  40.                    'DOSOPENQUEUE',
  41.                    selector(pid)||offset(pid)||
  42.                    selector(qhand)||offset(qhand)||
  43.                    selector(queue_name)||offset(queue_name))
  44.    if result <> 0 then sayerror 'Could not open 'queue_name; stop; endif
  45.  
  46.    /* Get number of items in queue */
  47.    nelements= '  '
  48.    result=dynalink('QUECALLS',
  49.                    'DOSQUERYQUEUE',
  50.                    qhand||
  51.                    selector(nelements)||offset(nelements))
  52.    if result <> 0 then
  53.       sayerror 'Error query queue'queue_name
  54.       call dynalink('QUECALLS', 'DOSCLOSEQUEUE', qhand)
  55.       stop
  56.    endif
  57.    /* Read all the elements from queue */
  58.    qinfo='    '
  59.    esize='  '
  60.    eaddr='    '
  61.    eprty='  '
  62.    i=.line
  63.    lc=itoa(nelements,10)
  64.    do n=1 to lc
  65.       /* Read queue */
  66.       result=dynalink('QUECALLS',
  67.                       'DOSREADQUEUE',
  68.                       qhand||
  69.                       selector(qinfo)||offset(qinfo)||
  70.                       selector(esize)||offset(esize)||
  71.                       selector(eaddr)||offset(eaddr)||
  72.                       atoi('0')||atoi('1')||
  73.                       selector(eprty)||offset(eprty)||
  74.                       atoi('0')||atoi('0'))
  75.       if result <> 0 then
  76.          sayerror 'Error reading queue' queue_name
  77.          call dynalink('QUECALLS', 'DOSCLOSEQUEUE', qhand)
  78.          stop
  79.       endif
  80.  
  81.       /* get access to buffer and insert it in current file */
  82.       bufhndl   = itoa(substr(eaddr, 3, 2), 10)
  83.       call buffer(GETBUF, bufhndl)
  84.       call buffer(FREEBUF, bufhndl)
  85.    enddo
  86.    call dynalink('QUECALLS', 'DOSCLOSEQUEUE', qhand)
  87.