home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / EHLLAPI.E < prev    next >
Text File  |  1996-04-22  |  11KB  |  224 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.  If the MYCNF.E indicates that E3EMUL.E is
  6. ; being used as the HOST_SUPPORT, then HLLAPI_CALL will not be
  7. ; duplicated here.
  8.  
  9. ; See also the LAMPDQ package, which provides a server for the VM host,
  10. ; and routines for executing host commands and seeing the output on the
  11. ; workstation.
  12.  
  13. ; By Larry Margolis
  14.  
  15. compile if not defined(SMALL)  -- Being compiled stand-alone?
  16.    include 'STDCONST.E'
  17.  define INCLUDING_FILE = 'EHLLAPI.E'
  18.    tryinclude 'MYCNF.E'          -- Get user's configuration.
  19.  
  20.  compile if not defined(SITE_CONFIG)
  21.     const SITE_CONFIG = 'SITECNF.E'
  22.  compile endif
  23.  compile if SITE_CONFIG
  24.     tryinclude SITE_CONFIG
  25.  compile endif
  26.  compile if not defined(HOST_SUPPORT)
  27.    const HOST_SUPPORT = 'STD'
  28.  compile endif
  29. compile endif
  30.  
  31. defc gethost          -- Get a copy of the host screen
  32.    EHLLAPI_data_string = 'A'            -- *** Connect to host PS ***
  33.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  34.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  35.    result=HLLAPI_call(atoi(1),
  36.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  37.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  38.    if result then
  39.       sayerror 'Error' result 'trying to connect to host session A.'
  40.       stop
  41.    endif
  42. ;                                       *** Copy host presentation space ***
  43.    bufhndl = buffer(CREATEBUF, 'HLLAPI', 1920)  -- get a buffer; assume 24x80
  44.    if not bufhndl then
  45.       sayerror 'CREATEBUF error number 'RC
  46.       call EHLLAPI_DISC()
  47.       stop
  48.    endif
  49.    EHLLAPI_data_string_length = atoi(1920)
  50.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  51.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  52.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  53.                                                -- (on return, RC)
  54.    if result=0 | result=4 | result=5 then
  55.       cur_pos = .line+1
  56.       do i=0 to 1840 by 80
  57.          insertline peek(bufhndl, i, 80),cur_pos
  58.          cur_pos=cur_pos+1
  59.       end
  60.    else
  61.       sayerror 'Error' result 'trying to copy host screen.'
  62.    endif
  63.    success = buffer(FREEBUF, bufhndl)
  64.    if not success then sayerror 'FREEBUF error number 'RC; endif
  65.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  66.  
  67. defc send_LAMSERV     -- Send the LAMSERV command to the  host screen
  68.    EHLLAPI_data_string = 'A'            -- *** Connect to host PS ***
  69.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  70.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  71.    result=HLLAPI_call(atoi(1),
  72.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  73.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  74.    if result then
  75.       sayerror 'Error' result 'trying to connect to host session A.'
  76.       stop
  77.    endif
  78. ;                                       *** Send key sequence to host ***
  79.    EHLLAPI_data_string = '@R@0@B@FLAMSERV@E'
  80. ; Reset, Home, Backtab, Erase_EOF, 'LAMSERV', Enter
  81. ; Should work from XEDIT as well as Ready prompt.  (Untested.)
  82.    EHLLAPI_data_string_length = atoi(length(EHLLAPI_data_string))
  83.    EHLLAPI_host_PS_position = atoi(0)   -- N/A
  84.    result=HLLAPI_call(atoi(3),
  85.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  86.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  87.    if result then
  88.       sayerror 'Error' result 'trying to send LAMSERV command.'
  89.       stop
  90.    endif
  91.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  92.  
  93.  
  94. defc testqs =         -- code 10 = Query sessions
  95.    EHLLAPI_data_string = substr('',1,120)
  96.    EHLLAPI_data_string_length = atoi(120) -- Data string length or buffer size
  97.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  98.  
  99.    result=HLLAPI_call(atoi(10),
  100.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  101.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  102. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  103.    insertline EHLLAPI_data_string
  104.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10) 'and length =' itoa(EHLLAPI_data_string_length,10)'.'
  105.  
  106. defc testqss =         -- code 22 = Query session status
  107.    EHLLAPI_data_string = substr('A',1,18)
  108.    EHLLAPI_data_string_length = atoi(18) -- Data string length or buffer size
  109.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  110.  
  111.    result=HLLAPI_call(atoi(22),
  112.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  113.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  114. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  115.    insertline EHLLAPI_data_string
  116.    rows = itoa(substr(EHLLAPI_data_string,12,2),10)
  117.    cols = itoa(substr(EHLLAPI_data_string,14,2),10)
  118.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10) 'and size =' rows 'x' cols'.'
  119.  
  120. defc testcon =         -- code 1 = Connect to presentation space
  121.    EHLLAPI_data_string = 'A'
  122.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  123.    EHLLAPI_host_PS_position = atoi(69)   -- Host presentation space position
  124.  
  125.    result=HLLAPI_call(atoi(1),
  126.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  127.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  128. ;  rc = itoa(EHLLAPI_host_PS_position,10)
  129.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  130.  
  131. defc testcopystring =         -- code 15 = Copy string
  132.    parse arg posn strng
  133.    EHLLAPI_data_string = strng
  134.    EHLLAPI_data_string_length = atoi(length(strng)) -- Data string length
  135.    EHLLAPI_host_PS_position = atoi(posn)   -- Host presentation space position
  136.  
  137.    result=HLLAPI_call(atoi(15),
  138.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  139.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  140.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  141.  
  142. defc testsendkey =         -- code 3 = Send key
  143.    EHLLAPI_data_string = arg(1)
  144.    EHLLAPI_data_string_length = atoi(length(arg(1))) -- Data string length
  145.    EHLLAPI_host_PS_position = atoi(0)   -- N/A
  146.  
  147.    result=HLLAPI_call(atoi(3),
  148.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  149.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  150.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  151.  
  152. defc testdisc =         -- code 2 = Disconnect from presentation space
  153.    result= EHLLAPI_DISC()
  154.    sayerror 'Result =' result
  155.  
  156. defproc EHLLAPI_DISC
  157.    EHLLAPI_data_string = ''
  158.    EHLLAPI_data_string_length = atoi(0) -- Data string length or buffer size
  159.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  160.  
  161.    return HLLAPI_call(atoi(2),
  162.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  163.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  164.  
  165. defc test_copy_PS=         -- code 5 = Copy presentation space
  166. ;  EHLLAPI_data_string = substr('',1,1920)  -- Assume 24x80 screen
  167.    bufhndl = buffer(CREATEBUF, 'HLLAPI', 1920)  -- get a buffer
  168.    if not bufhndl then sayerror 'CREATEBUF error number 'RC; stop; endif
  169.    EHLLAPI_data_string_length = atoi(1920)
  170.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  171.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  172.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  173.                                                -- (on return, RC)
  174.    cur_pos = .line+1
  175.    if result=0 | result=4 | result=5 then
  176.       do i=0 to 1840 by 80
  177.          insertline peek(bufhndl, i, 80),cur_pos
  178.          cur_pos=cur_pos+1
  179.       end
  180.    endif
  181.    sayerror 'Result =' result 'and RC =' itoa(EHLLAPI_host_PS_position,10)'.'
  182.    success = buffer(FREEBUF, bufhndl)
  183.    if not success then sayerror 'FREEBUF error number 'RC; stop; endif
  184.  
  185. compile if HOST_SUPPORT <> 'EMUL'
  186. ; HLLAPI_call is the general interface for calling the EHLLAPI dynalink.
  187. ; Parameters are always the same - an EHLLAPI function number, selector of
  188. ; the data string, offset of the data string, the data string length, and
  189. ; the host presentation space position.  They might not be used in all calls,
  190. ; but EHLLAPI requires that they all be present.
  191. ;
  192. ; The data string is passed via selector and offset rather than as a VAR string,
  193. ; since some calls (e.g., copying the entire host screen) require a string
  194. ; larger than 255 bytes, and so we must allocate a buffer and pass that.
  195. defproc HLLAPI_call(EHLLAPI_function_number,
  196.                     sel_EHLLAPI_data_string, ofs_EHLLAPI_data_string,
  197.                 var EHLLAPI_data_string_length, -- Data str. len. or buffer size
  198.                 var EHLLAPI_host_PS_position)   -- Host presentation space posn.
  199.                                                 -- (on return, RC)
  200.    rc = 0        -- Prepare for missing DLL library
  201.  compile if EPM32
  202.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  203.                    'HLLAPI',                    -- HLLAPI direct call
  204.                     Thunk(address(EHLLAPI_function_number))    ||
  205.                     Thunk(ofs_EHLLAPI_data_string              || sel_EHLLAPI_data_string)  ||
  206.                     Thunk(address(EHLLAPI_data_string_length)) ||
  207.                     Thunk(address(EHLLAPI_host_PS_position)) )
  208.  compile else
  209.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  210.                    'HLLAPI',                    -- HLLAPI direct call
  211.                    address(EHLLAPI_function_number)     ||
  212.                    sel_EHLLAPI_data_string              ||
  213.                    ofs_EHLLAPI_data_string              ||
  214.                    address(EHLLAPI_data_string_length)  ||
  215.                    address(EHLLAPI_host_PS_position))
  216.  compile endif
  217.  compile if EPM
  218.    if rc then sayerror ERROR__MSG rc FROM_HLLAPI__MSG '-' sayerrortext(rc); stop; endif
  219.  compile else
  220.    if rc then sayerror ERROR__MSG rc FROM_HLLAPI__MSG; stop; endif
  221.  compile endif
  222.    return itoa(EHLLAPI_host_PS_position, 10)
  223. compile endif -- HOST_SUPPORT not EMUL
  224.