home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epm603a.zip / EPMSMP.ZIP / EHLLAPI.E < prev    next >
Text File  |  1992-08-26  |  9KB  |  194 lines

  1. ; The following contains samples of various EHLLAPI calls to
  2. ; allow EPM to interact with the Communications Manager.  This
  3. ; is a stand-alone file; note that E3EMUL.E includes both the
  4. ; HLLAPI_CALL routine and a simpler interface for calls that
  5. ; don't return data.
  6.  
  7. ; By Larry Margolis
  8.  
  9. compile if not defined(CREATEBUF)
  10.    include 'STDCONST.E'
  11. compile endif
  12.  
  13. defc gethost          -- Get a copy of the host screen
  14.    EHLLAPI_data_string = 'A'            -- *** Connect to host PS ***
  15.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  16.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  17.    result=HLLAPI_call(atoi(1),
  18.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  19.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  20.    if result then
  21.       sayerror 'Error' result 'trying to connect to host session A.'
  22.       stop
  23.    endif
  24. ;                                       *** Copy host presentation space ***
  25.    bufhndl = buffer(CREATEBUF, 'HLLAPI', 1920)  -- get a buffer; assume 24x80
  26.    if not bufhndl then
  27.       sayerror 'CREATEBUF error number 'RC
  28.       call EHLLAPI_DISC()
  29.       stop
  30.    endif
  31.    EHLLAPI_data_string_length = atoi(1920)
  32.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  33.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  34.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  35.                                                -- (on return, RC)
  36.    if result=0 | result=4 | result=5 then
  37.       cur_pos = .line+1
  38.       do i=0 to 1840 by 80
  39.          insertline peek(bufhndl, i, 80),cur_pos
  40.          cur_pos=cur_pos+1
  41.       end
  42.    else
  43.       sayerror 'Error' result 'trying to copy host screen.'
  44.    endif
  45.    success = buffer(FREEBUF, bufhndl)
  46.    if not success then sayerror 'FREEBUF error number 'RC; endif
  47.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  48.  
  49. defc send_LAMSERV     -- Send the LAMSERV command to the  host screen
  50.    EHLLAPI_data_string = 'A'            -- *** Connect to host PS ***
  51.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  52.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  53.    result=HLLAPI_call(atoi(1),
  54.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  55.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  56.    if result then
  57.       sayerror 'Error' result 'trying to connect to host session A.'
  58.       stop
  59.    endif
  60. ;                                       *** Send key sequence to host ***
  61.    EHLLAPI_data_string = '@R@0@B@FLAMSERV@E'
  62. ; Reset, Home, Backtab, Erase_EOF, 'LAMSERV', Enter
  63. ; Should work from XEDIT as well as Ready prompt.  (Untested.)
  64.    EHLLAPI_data_string_length = atoi(length(EHLLAPI_data_string))
  65.    EHLLAPI_host_PS_position = atoi(0)   -- N/A
  66.    result=HLLAPI_call(atoi(3),
  67.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  68.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  69.    if result then
  70.       sayerror 'Error' result 'trying to send LAMSERV command.'
  71.       stop
  72.    endif
  73.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  74.  
  75.  
  76. defc testqs =         -- code 10 = Query sessions
  77.    EHLLAPI_data_string = substr('',1,120)
  78.    EHLLAPI_data_string_length = atoi(120) -- Data string length or buffer size
  79.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  80.  
  81.    result=HLLAPI_call(atoi(10),
  82.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  83.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  84. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  85.    insertline EHLLAPI_data_string
  86.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10) 'and length =' itoa(EHLLAPI_data_string_length,10)'.'
  87.  
  88. defc testqss =         -- code 22 = Query session status
  89.    EHLLAPI_data_string = substr('A',1,18)
  90.    EHLLAPI_data_string_length = atoi(18) -- Data string length or buffer size
  91.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  92.  
  93.    result=HLLAPI_call(atoi(22),
  94.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  95.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  96. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  97.    insertline EHLLAPI_data_string
  98.    rows = itoa(substr(EHLLAPI_data_string,12,2),10)
  99.    cols = itoa(substr(EHLLAPI_data_string,14,2),10)
  100.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10) 'and size =' rows 'x' cols'.'
  101.  
  102. defc testcon =         -- code 1 = Connect to presentation space
  103.    EHLLAPI_data_string = 'A'
  104.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  105.    EHLLAPI_host_PS_position = atoi(69)   -- Host presentation space position
  106.  
  107.    result=HLLAPI_call(atoi(1),
  108.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  109.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  110. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  111.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  112.  
  113. defc testcopystring =         -- code 15 = Copy string
  114.    parse arg posn strng
  115.    EHLLAPI_data_string = strng
  116.    EHLLAPI_data_string_length = atoi(length(strng)) -- Data string length
  117.    EHLLAPI_host_PS_position = atoi(posn)   -- Host presentation space position
  118.  
  119.    result=HLLAPI_call(atoi(15),
  120.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  121.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  122.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  123.  
  124. defc testsendkey =         -- code 3 = Send key
  125.    EHLLAPI_data_string = arg(1)
  126.    EHLLAPI_data_string_length = atoi(length(arg(1))) -- Data string length
  127.    EHLLAPI_host_PS_position = atoi(0)   -- N/A
  128.  
  129.    result=HLLAPI_call(atoi(3),
  130.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  131.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  132.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  133.  
  134. defc testdisc =         -- code 2 = Disconnect from presentation space
  135.    result= EHLLAPI_DISC()
  136.    sayerror 'Result =' result
  137.  
  138. defproc EHLLAPI_DISC
  139.    EHLLAPI_data_string = ''
  140.    EHLLAPI_data_string_length = atoi(0) -- Data string length or buffer size
  141.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  142.  
  143.    return HLLAPI_call(atoi(2),
  144.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  145.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  146.  
  147. defc test_copy_PS=         -- code 5 = Copy presentation space
  148. ;  EHLLAPI_data_string = substr('',1,1920)  -- Assume 24x80 screen
  149.    bufhndl = buffer(CREATEBUF, 'HLLAPI', 1920)  -- get a buffer
  150.    if not bufhndl then sayerror 'CREATEBUF error number 'RC; stop; endif
  151.    EHLLAPI_data_string_length = atoi(1920)
  152.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  153.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  154.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  155.                                                -- (on return, RC)
  156.    cur_pos = .line+1
  157.    if result=0 | result=4 | result=5 then
  158.       do i=0 to 1840 by 80
  159.          insertline peek(bufhndl, i, 80),cur_pos
  160.          cur_pos=cur_pos+1
  161.       end
  162.    endif
  163.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  164.    success = buffer(FREEBUF, bufhndl)
  165.    if not success then sayerror 'FREEBUF error number 'RC; stop; endif
  166.  
  167. ; HLLAPI_call is the general interface for calling the EHLLAPI dynalink.
  168. ; Parameters are always the same - an EHLLAPI function number, selector of
  169. ; the data string, offset of the data string, the data string length, and
  170. ; the host presentation space position.  They might not be used in all calls,
  171. ; but EHLLAPI requires that they all be present.
  172. ;
  173. ; The data string is passed via selector and offset rather than as a VAR string,
  174. ; since some calls (e.g., copying the entire host screen) require a string
  175. ; larger than 255 bytes, and so we must allocate a buffer and pass that.
  176. defproc HLLAPI_call(EHLLAPI_function_number,
  177.                     sel_EHLLAPI_data_string, ofs_EHLLAPI_data_string,
  178.                 var EHLLAPI_data_string_length, -- Data str. len. or buffer size
  179.                 var EHLLAPI_host_PS_position)   -- Host presentation space posn.
  180.                                                 -- (on return, RC)
  181.    rc = 0        -- Prepare for missing DLL library
  182.    result=dynalink('ACS3EHAP',     /* dynamic link library name       */
  183.                    'HLLAPI',       /* HLLAPI direct call              */
  184.                    selector(EHLLAPI_function_number)||
  185.                    offset(EHLLAPI_function_number)||
  186.                    sel_EHLLAPI_data_string||
  187.                    ofs_EHLLAPI_data_string||
  188.                    selector(EHLLAPI_data_string_length)||
  189.                    offset(EHLLAPI_data_string_length)||
  190.                    selector(EHLLAPI_host_PS_position)||
  191.                    offset(EHLLAPI_host_PS_position))
  192.    if rc then sayerror 'Error' rc 'from HLLAPI dynalink call.'; stop; endif
  193.    return result
  194.