Attribute VB_Name = "HLLCALLS"
'*****************************************************************************************************
'  The following declaration defines the interface to the EHLLAPI DLL. Note that the
'  function name and DLL are different for WIN32 and WIN16
'*****************************************************************************************************

' If using EHLLAPI 16-Bit, use the following declarations
'Declare Sub HLLAPI Lib "ACS3EHAP.DLL" (iFunction As Integer, ByVal lpData As String, ilength As Integer, iRc As Integer)
'Declare Sub HLLAPIAny Lib "ACS3EHAP.DLL" (iFunction As Integer, lpData As Any, ilength As Integer, iRc As Integer)

' If using EHLLAPI 32-Bit, use the following declarations
'Declare Sub HLLAPI Lib "EHLLAP32.DLL" Alias "HLLAPI32" (iFunction As Integer, ByVal lpData As String, ilength As Integer, iRc As Integer)
'Declare Sub HLLAPIAny Lib "EHLLAP32.DLL" Alias "HLLAPI32" (iFunction As Integer, lpData As Any, ilength As Integer, iRc As Integer)

' If using WinHLLAPI (16-Bit or 32-Bit), use the following declarations
Declare Sub HLLAPI Lib "WHLLAP32.DLL" Alias "WinHLLAPI" (iFunction As Integer, ByVal lpData As String, ilength As Integer, iRc As Integer)
Declare Sub HLLAPIAny Lib "WHLLAP32.DLL" Alias "WinHLLAPI" (iFunction As Integer, lpData As Any, ilength As Integer, iRc As Integer)
Declare Function WinHLLAPIStartup Lib "WHLLAP32.DLL" (iFunction As Integer, lpData As Any) As Integer
Declare Sub WinHLLAPICleanup Lib "WHLLAP32.DLL" ()

'*****************************************************************************************************
'  The following constants are used by the EHLLAPIWait function
'*****************************************************************************************************

Global Const EHLLAPI_TWAIT = 1
Global Const EHLLAPI_LWAIT = 2
Global Const EHLLAPI_NWAIT = 3

'*****************************************************************************************************
'  The following constants are used by various search functions
'*****************************************************************************************************

Global Const EHLLAPI_NEXTFIELD = "__"
Global Const EHLLAPI_NEXTPROT = "NP"
Global Const EHLLAPI_NEXTUNPROT = "NU"
Global Const EHLLAPI_PREVFIELD = "P_"
Global Const EHLLAPI_PREVPROT = "PP"
Global Const EHLLAPI_PREVUNPROT = "PU"

Type PMWINDOWSTATUS
        PSName As String * 1
        queryMode As Byte
        queryStatus As Integer
        xPos As Integer
        yPos As Integer
        xSize As Integer
        ySize As Integer
        tileOrder As Long
End Type

Type WHLLAPIDATA
    wVersion As Integer
    szDescription As String * 128
End Type

Type AUTOSTART
    cPSID As String * 1
    cModelType As String * 1
    cResrvd1 As String * 1
    cResrvd2 As String * 1
    cResrvd3 As String * 1
    cHostName As String * 128
End Type
    
Type QRYSTATUSEXT
  cPSID As String * 1             '// Session Short Name
  cStatus As String * 1           '// Status - 'I', 'R', 'C'
  cTerminalType As String * 1     '// Terminal Type - '3', '5', 'V'
  cReserved3 As String * 1            '// Reserved 3
  acHostName As String * 256      '// Configured Session Host Name/Address
  acProfile As String * 256       '// Configured Session Profile
  acLUName As String * 16         '// Active LU name for session
  hWnd As Variant                     '// Current window handle - was DWORD
  dwHostIP As Long                 '// Host IP Address - was DWORD
End Type

    
Public Const PMWS_CHANGEWINDOWSIZE = &H1
Public Const PMWS_MOVEWINDOW = &H2
Public Const PMWS_CHANGEZORDER = &H4
Public Const PMWS_VISIBLE = &H8
Public Const PMWS_INVISIBLE = &H10
Public Const PMWS_ACTIVATE = &H80
Public Const PMWS_DEACTIVATE = &H100
Public Const PMWS_MINIMIZE = &H400
Public Const PMWS_MAXIMIZE = &H800
Public Const PMWS_RESTORE = &H1000

Public Const PMWS_SET = &H1
Public Const PMWS_QUERY = &H2

'***********************************************************************
'
' EHLLAPICloseWindow                This function is used to close
'                                   a PS which is open (connected or not).
'
'   Return: 0 - Window closed
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPICloseWindow(idSession As String) As Integer
    Dim iRc As Integer

    HLLAPI 201, Left$(idSession, 1), 1, iRc

    EHLLAPICloseWindow = iRc
End Function

'***********************************************************************
'
' EHLLAPIConnect                    This function is used to connect
'                                   to a logical session.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Invalid presentation space
'           5 - Connected successfully but PS Keyboard is Locked
'           9 - System Error - DLL probably not loaded
'          11 - Resource is not available. Host PS is already in use
'               by another program.
'
'***********************************************************************
'
Function EHLLAPIConnect(idSession As String, iPhysical As Integer) As Integer
    Dim iRc As Integer
    Dim ConnMode As String
    Dim iParmsSet As Integer

    If iPhysical = 1 Then
      ConnMode = "CONPHYS"
    Else
      ConnMode = "CONLOG"
    End If

    iParmsSet = Len(ConnMode)

    HLLAPI 9, ConnMode, iParmsSet, iRc

    HLLAPI 1, Left$(idSession, 1), 1, iRc

    EHLLAPIConnect = iRc
End Function

'***********************************************************************
'
' EHLLAPIConnect2                    This function is used to connect
'                                   to a logical session.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Invalid presentation space
'           5 - Connected successfully but PS Keyboard is Locked
'           9 - System Error - DLL probably not loaded
'          11 - Resource is not available. Host PS is already in use
'               by another program.
'
'***********************************************************************
'
Function EHLLAPIConnect2(astrct As AUTOSTART, iPhysical As Integer) As Integer
    Dim iRc As Integer
    Dim ConnMode As String
    Dim iParmsSet As Integer

    If iPhysical = 1 Then
      ConnMode = "CONPHYS"
    Else
      ConnMode = "CONLOG"
    End If

    iParmsSet = Len(ConnMode)

    HLLAPI 9, ConnMode, iParmsSet, iRc

    HLLAPIAny 1, astrct, Len(astrct), iRc

'    EHLLAPIConnect = iRc
End Function

'***********************************************************************
'
' EHLLAPIConnectPMWindowServices    This function is used to connect
'                                   to a logical session's window service.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Invalid presentation space
'           5 - Connected successfully but PS Keyboard is Locked
'           9 - System Error - DLL probably not loaded
'          11 - Resource is not available. Host PS is already in use
'               by another program.
'
'***********************************************************************
'
Function EHLLAPIConnectPMWindowServices(idSession As String) As Integer
    Dim iRc As Integer

    HLLAPI 101, Left$(idSession, 1), 1, iRc

    EHLLAPIConnectPMWindowServices = iRc
End Function

'***********************************************************************
'
' EHLLAPIConvertPositionToRowCol    This function is used to convert
'                                   a PS Position into a Row,Col value.
'
'   Return: 0 - Always
'
'***********************************************************************
'
Function EHLLAPIConvertPositionToRowCol(idSession As String, iPos As Integer, iRow As Integer, iColumn As Integer) As Integer
    Dim iRc As Integer
    Dim strMode As String

    strMode = Left$(idSession, 1) & "P"
    iRc = iPos

    HLLAPI 99, strMode, iRow, iRc

    iColumn = iRc

    EHLLAPIConvertPositionToRowCol = 0
End Function

'***********************************************************************
'
' EHLLAPIConvertRowColToPosition    This function is used to convert
'                                   a Row,Col value into a PS Position.
'
'   Return: PS Position
'
'***********************************************************************
'
Function EHLLAPIConvertRowColToPosition(idSession As String, iRow As Integer, iColumn As Integer) As Integer
    Dim iRc As Integer
    Dim strMode As String

    strMode = Left$(idSession, 1) & "R"
    iRc = iColumn

    HLLAPI 99, strMode, iRow, iRc

    EHLLAPIConvertRowColToPosition = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyFieldToString          This function is used to copy a portion
'                                   of a field back into a string.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - Parameter error
'           6 - String and field lengths are not equal
'           7 - Invalid PS
'           9 - System Error - DLL probably not loaded
'          24 - Unformatted PS
'
'***********************************************************************
'
Function EHLLAPICopyFieldToString(strString As String, iMaxLen As Integer, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 3564

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

    iRc = iPos       ' Start at specified position

    HLLAPI 34, strTemp, iMaxLen, iRc

' Copy the string back if there were no errors

    If iRc = 0 Then
      strString = strTemp
    End If

    EHLLAPICopyFieldToString = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyOIA                    This function is used to copy the
'                                   Operator Information Area to a string.
'                                   Don't forget that the string returned is
'                                   NOT in ASCII!
'
'   Return: 0 - OIA copied successfully
'           1 - Not connected to PS
'           2 - Invalid string length (OIA data not returned)
'           4 - OIA copied, PS is busy
'           5 - OIA copied, but PS Keyboard is Locked
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPICopyOIA(strOIA As String) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 103

    HLLAPI 13, strTemp, 103, iRc

' Copy the string back if there were no errors

    If iRc = 0 Or iRc = 5 Then
       strOIA = strTemp
    End If

    EHLLAPICopyOIA = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyPS                     This function is used to copy the
'                                   entire presentation space to a string.
'
'   Return: 0 - Presentation Space copied successfully
'           1 - Not connected to PS
'           2 - Error with string length
'           4 - Copied; waiting for host response
'           5 - Copied; keyboard locked
'           6 - Data may be truncated
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPICopyPS(strScreen As String) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 3564

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

    HLLAPI 5, strTemp, 0, iRc

' Copy the string back if there were no errors

    If iRc = 0 Or iRc = 5 Or iRc = 101 Then
      strScreen = strTemp
    End If

    EHLLAPICopyPS = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyPSToString             This function is used to copy a portion
'                                   of the Presentation Space to the string.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - Incorrect string length
'           4 - Copied; waiting for host response
'           5 - Copied; keyboard locked
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPICopyPSToString(strScreen As String, iMaxLen As Integer, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 3564

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

    iRc = iPos       ' Start at specified position

    HLLAPI 8, strTemp, iMaxLen, iRc

' Copy the string back if there were no errors

    If iRc = 0 Or iRc = 5 Or iRc = 101 Then
      strScreen = strTemp
    End If

    EHLLAPICopyPSToString = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyStringToField          This function is used to copy a string
'                                   into a field in the Presentation Space.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - Parameter error
'           5 - PS is locked; bad data sent
'           6 - Copied; data truncated
'           7 - PS position invalid
'           9 - System Error - DLL probably not loaded
'          24 - Unformatted PS
'
'***********************************************************************
'
Function EHLLAPICopyStringToField(strString As String, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

    iStrLen = Len(strString)
    iRc = iPos       ' Start at specified position

    HLLAPI 33, strString, iStrLen, iRc

    EHLLAPICopyStringToField = iRc
End Function

'***********************************************************************
'
' EHLLAPICopyStringToPS             This function is used to copy a string
'                                   to the Presentation Space at the specified
'                                   PS position.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - Incorrect string length
'           5 - Illegal data; keyboard locked
'           6 - Success; data truncated
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPICopyStringToPS(strString As String, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

    iStrLen = Len(strString)
    iRc = iPos       ' Start at specified position

    HLLAPI 15, strString, iStrLen, iRc

    EHLLAPICopyStringToPS = iRc
End Function

'***********************************************************************
'
' EHLLAPIDisconnect                 This function is used to disconnect
'                                   from a logical session.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Not connected to any PS
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIDisconnect(idSession As String) As Integer
    Dim iRc As Integer

    HLLAPI 2, Left$(idSession, 1), 1, iRc

    EHLLAPIDisconnect = iRc
End Function

'***********************************************************************
'
' EHLLAPIDisconnectPMWindowServices This function is used to disconnect
'                                   from a logical session's window services.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Not connected to any PS
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIDisconnectPMWindowServices(idSession As String) As Integer
    Dim iRc As Integer

    HLLAPI 102, Left$(idSession, 1), 1, iRc

    EHLLAPIDisconnectPMWindowServices = iRc
End Function

'***********************************************************************
'
' EHLLAPIFindFieldPosition          This function is used to get the field
'                                   address of the next or previous field.
'
'   Return: 0 - Field address located successfully
'           1 - Not connected to PS
'           2 - Parameter error
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'          24 - No such field
'          28 - Field length = 0
'
'***********************************************************************
'
Function EHLLAPIFindFieldPosition(strSearchType As String, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim iFldPos As Integer

    iFldPos = 0
    iRc = iPos

    HLLAPI 31, strSearchType, iFldPos, iRc

' Set the field position if there were no errors

    If iRc = 0 Then
       iPos = iFldPos
    Else
       iPos = 0
    End If

    EHLLAPIFindFieldPosition = iRc
End Function

'***********************************************************************
'
' EHLLAPIGetRowString               This function is used to get the n'th
'                                   row of data into the specified string.
'
'   Return: 0 - String returned successfully
'           5 - String copied; keyboard locked
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIGetRowString(idSession As String, strString As String, iRow As Integer) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 3564
    Dim iRowSize

' First, set the session to not accept EABs, no translation, and no attributes

    strParms$ = "NOATTRB,NOEAB,XLATE"
    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

' Now query the terminal model to get the number of columns

    iRc = EHLLAPIQuerySessionStatus(Left$(idSession, 1), strLongName$, iRows%, iColumns%)

    iRc = (iRow - 1) * iColumns% + 1

    HLLAPI 8, strTemp, iColumns%, iRc

' Copy the string back if there were no errors

    If iRc = 0 Or iRc = 5 Or iRc = 101 Then
      strString = strTemp
    End If

    EHLLAPIGetRowString = iRc
End Function

'***********************************************************************
'
' EHLLAPIGetVersion                 This function is used to get
'                                   the version number of the EHLLAPI
'                                   interface.
'
'   Return: 0 - Version number retrieved successfully
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIGetVersion(hiVer As Integer, loVer As Integer) As Integer
    Dim iRc As Integer
    Dim Answer As String * 35

    HLLAPI 20, Answer, 35, iRc

'IF there were no errors, return the version numbers

    If iRc = 0 Then
      hiVer = Asc(Mid(Answer, 1, 1))
      loVer = Asc(Mid(Answer, 2, 1))
      EHLLAPIGetVersion = 0
    Else
      EHLLAPIGetVersion = iRc
    End If
End Function

'***********************************************************************
'
' EHLLAPIPause                      This function is used to pause
'                                   for a given number of half-second
'                                   increments
'
'   Return: 0 - Successful
'           9 - System Error - DLL probably not loaded
'          26 - PS and/or OIA has been updated
'
'***********************************************************************
'
Function EHLLAPIPause(iHalfSeconds As Integer) As Integer
    Dim iWaitHalfSeconds As Integer
    Dim iRc As Integer

    iWaitHalfSeconds = iHalfSeconds

    HLLAPI 18, "", iWaitHalfSeconds, iRc

    EHLLAPIPause = iRc
End Function

'***********************************************************************
'
' EHLLAPIPMWindowStatus             This function is used to change a
'                                   windows's PS size, location, or visible
'                                   state.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - You specified an invalid option
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIPMWindowStatus(pmStatus As PMWINDOWSTATUS) As Integer
    Dim iRc As Integer
    Dim iLen As Integer

    iLen = 16

    HLLAPIAny 104, pmStatus, iLen, iRc

    EHLLAPIPMWindowStatus = iRc
End Function

'***********************************************************************
'
' EHLLAPIQueryCursorLocation        This function is used to get
'                                   the current cursor location. The
'                                   position returned is between
'                                   1 and the PS size (1920, 2560, 3440,
'                                   or 3564).
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIQueryCursorLocation(iPos As Integer) As Integer
    Dim iRc As Integer

    HLLAPI 7, "", iPos, iRc

    EHLLAPIQueryCursorLocation = iRc
End Function

'***********************************************************************
'
' EHLLAPIQueryFieldAttribute        This function is used to get
'                                   the attribute value at the specified
'                                   PS position.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           7 - PS position is invalid
'           9 - System Error - DLL probably not loaded
'          24 - PS not formatted
'
'***********************************************************************
'
Function EHLLAPIQueryFieldAttribute(iPos As Integer, iAttr As Integer) As Integer
    Dim iRc As Integer

    iRc = iPos

    HLLAPI 14, "", iAttr, iRc

    EHLLAPIQueryFieldAttrbute = iRc
End Function

'***********************************************************************
'
' EHLLAPIQuerySessions              This function is used to get
'                                   a list of all session short names
'                                   that are currently available. The
'                                   function returns a string such as
'                                   "AB" meaning that sessions "A" and
'                                   "B" are available for use.
'
'   Return: 0 - Successful
'           2 - Invalid string length
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIQuerySessions(strAllSessions As String) As Integer
    Dim iRc As Integer
    Dim iNumSessions As Integer
    Dim Answer As String * 312

    iNumSessions = 312

    HLLAPI 10, Answer, iNumSessions, iRc

    strAllSessions = ""

' If there were no errors, then build the string of session short names

    If iRc = 0 Then
       For i = 0 To iNumSessions
          strAllSessions = strAllSessions & Mid$(Answer, i * 12 + 1, 1)
       Next i

       EHLLAPIQuerySessions = 0
    Else
       EHLLAPIQuerySessions = iRc
    End If
End Function

'***********************************************************************
'
' EHLLAPIQuerySessionStatus         This function is used to get
'                                   the status of the session specified.
'                                   The session longname and size (row and
'                                   columns) are returned.
'
'   Return: 0 - Session info retrieved successfully
'           1 - Invalid session
'           2 - Invalid request
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIQuerySessionStatus(idSession As String, strLongName As String, iRows As Integer, iColumns As Integer) As Integer
    Dim iRc As Integer
    Dim Answer As String * 18

    Answer = Left$(idSession, 1)

    HLLAPI 22, Answer, 18, iRc

' If there were no errors, then return the session information

    If (iRc = 0) Then
       strLongName = Mid$(Answer, 2, 8)
       iColumns = Asc(Mid(Answer, 14, 1))
       iRows = Asc(Mid(Answer, 12, 1))

       EHLLAPIQuerySessionStatus = 0
    Else
       EHLLAPIQuerySessionStatus = iRc
    End If
End Function


'***********************************************************************
'
' EHLLAPIQuerySessionStatusEXTENDED   This function is used to get
'                                     the status of the session specified.
'
'
'   Return: 0 - Session info retrieved successfully
'           1 - Invalid session
'           2 - Invalid request
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
'Function EHLLAPIQuerySessionStatusEx(ByRef strConnStatus As String, ByRef strShortName As String, ByRef strType As String, _
'        ByRef strHostName As String, ByRef strProfile As String, ByRef strLUName As String) As Integer
Function EHLLAPIQuerySessionStatusEx(Answer As QRYSTATUSEXT) As QRYSTATUSEXT
    Dim iRc As Integer
         
    HLLAPIAny 202, Answer, Len(Answer), iRc

' If there were no errors, then return the session information

    If (iRc = 0) Then
    
       'strConnStatus = Answer.cStatus
       'strShortName = Answer.cPSID
       'strType = Answer.cTerminalType
       'strHostName = Answer.acHostName
       'strProfile = Answer.acProfile
       'strLUName = Answer.acLUName
       
       EHLLAPIQuerySessionStatusEx = Answer
    Else
       MsgBox "EHLLAPI Error in 202 - " + Str(iRc)
       'EHLLAPIQuerySessionStatusEx = iRc
    End If
End Function
    



'***********************************************************************
'
' EHLLAPIReceiveFile                This function is used to receive a
'                                   file from the host system.
'
'   Return: 0 - Successful
'           2 - Parameter error
'           3 - File transfer complete
'           4 - File transfer complete; records segmented
'           9 - System Error - DLL probably not loaded
'         302 - File not found
'         305 - Access denied
'
'***********************************************************************
'
Function EHLLAPIReceiveFile(strPCFileName As String, idSession As String, strHostFilename As String, strOptions As String) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer
    Dim strCommand As String

    strCommand = strPCFileName & " " & Left$(idSession, 1) & ":" & strHostFilename & " " & strOptions
    iStrLen = Len(strCommand)

    HLLAPI 91, strCommand, iStrLen, iRc

    EHLLAPIReceiveFile = iRc
End Function

'***********************************************************************
'
' EHLLAPIRelease                    This function is used to unlock the
'                                   user window to allow user input from
'                                   the keyboard.
'
'   Return: 0 - Presentation Space unlocked
'           1 - Not connected to PS
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIRelease() As Integer
   Dim iRc As Integer

   HLLAPI 12, "", 0, iRc

   EHLLAPIRelease = iRc
End Function

'***********************************************************************
'
' EHLLAPIReserve                    This function is used to lock the
'                                   user window to prevent user input from
'                                   the keyboard.
'
'   Return: 0 - Presentation space locked
'           1 - Not connected to PS
'           5 - Presentation Space keyboard locked
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIReserve() As Integer
   Dim iRc As Integer

   HLLAPI 11, "", 0, iRc

   EHLLAPIReserve = iRc
End Function

'***********************************************************************
'
' EHLLAPIReset                      This function is used to reset
'                                   the EHLLAPI interface back to default
'                                   specifications.
'
'   Return: 0 - Reset performed successfully
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIReset() As Integer
   Dim iRc As Integer
   Dim Answer As String * 35

   HLLAPI 21, Answer, 0, iRc

   EHLLAPIReset = iRc
End Function

'***********************************************************************
'
' EHLLAPISearchField                This function is used to search a field
'                                   for the specified text string.
'
'   Return: 0 - String located withing field
'           1 - Not connected to PS
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'          24 - String was not found
'
'***********************************************************************
'
Function EHLLAPISearchField(strString As String, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer

    iStrLen = Len(strString)
    iRc = iPos

    HLLAPI 30, strString, iStrLen, iRc

' If there were no errors, then return the position of the string

    If iRc = 0 Then
       iPos = iStrLen
    Else
       iPos = 0
    End If

    EHLLAPISearchField = iRc
End Function

'***********************************************************************
'
' EHLLAPISearchPS                   This function is used to search the
'                                   presentation space for the given
'                                   string.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           2 - Parameter error
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'          24 - String was not found
'
'***********************************************************************
'
Function EHLLAPISearchPS(strString As String, iPos As Integer) As Integer
    Dim iRc As Integer
    Dim iFoundPos As Integer

    iFoundPos = Len(strString)
    iRc = iPos

    HLLAPI 6, strString, iFoundPos, iRc

' If there were no errors, then return the position of the string

    If (iRc = 0) Then
       iPos = iFoundPos
    Else
       iPos = 0
    End If

    EHLLAPISearchPS = iRc
End Function

'***********************************************************************
'
' EHLLAPISendFile                   This function is used to send a PC
'                                   file up to the host system.
'
'   Return: 0 - Successful
'           2 - Parameter error
'           3 - File transfer complete
'           4 - File transfer complete; records segmented
'           9 - System Error - DLL probably not loaded
'         302 - File not found
'         305 - Access denied
'
'***********************************************************************
'
Function EHLLAPISendFile(strPCFileName As String, idSession As String, strHostFilename As String, strOptions As String) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer
    Dim strCommand As String

    strCommand = strPCFileName & " " & Left$(idSession, 1) & ":" & strHostFilename & " " & strOptions
    iStrLen = Len(strCommand)

    HLLAPI 90, strCommand, iStrLen, iRc

    EHLLAPISendFile = iRc
End Function

'***********************************************************************
'
' EHLLAPISendKey                    This function is used to send key
'                                   sequences to a logical session.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Not connected to PS
'           2 - Incorrect parameter
'           4 - Host session is busy; not all keystrokes could be sent
'           5 - Host session is locked; not all keystrokes could be sent
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPISendKey(strKeyString As String) As Integer
    Dim iRc As Integer
    Dim iStrLen As Integer

    iStrLen = Len(strKeyString)

    HLLAPI 3, strKeyString, iStrLen, iRc

    EHLLAPISendKey = iRc
End Function

'***********************************************************************
'
' EHLLAPISetCursorLocation          This function is used to set the new
'                                   cursor location.
'
'   Return: 0 - Version number retrieved successfully
'           1 - Not connected to PS
'           4 - Host session is busy
'           7 - Invalid PS position
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPISetCursorLocation(iNewPos As Integer) As Integer
    Dim iRc As Integer

    iRc = iNewPos

    HLLAPI 40, "", 0, iRc

    EHLLAPISetCursor = iRc
End Function

'***********************************************************************
'
' EHLLAPISetSessionParameters       This function is used to set
'                                   session parameters in the EHLLAPI
'                                   interface. The string "strParameters"
'                                   contains a comma separated list of
'                                   commands to set
'
'   Return: 0 - All parameters were set properly
'           2 - One or more unrecognized parameter values; all recognized values accepted
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPISetSessionParameters(strParameters As String) As Integer
    Dim iRc As Integer
    Dim iParmsSet As Integer

    iParmsSet = Len(strParameters)

    HLLAPI 9, strParameters, iParmsSet, iRc

    EHLLAPISetSessionParameters = iRc
End Function

'***********************************************************************
'
' EHLLAPIWait                       This function is used to wait
'                                   for a host event to occur.
'
'   Return: 0 - Successful
'           1 - Not connected to PS
'           4 - Time out on TWAIT and LWAIT
'           5 - Presentation Space keyboard locked
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIWait(iWaitType As Integer) As Integer
    Dim iRc As Integer
    Dim strTemp As String * 3564

' First, set the appropriate type of system wait

    If iWaitType = EHLLAPI_TWAIT Then
      strParms$ = "TWAIT"
    ElseIf iWaitType = EHLLAPI_LWAIT Then
      strParms$ = "LWAIT"
    Else
      strParms$ = "NWAIT"
    End If

    iParmsSet% = Len(strParms$)

    HLLAPI 9, strParms$, iParmsSet%, iRc

' now WAIT!

    HLLAPI 4, "", 0, iRc

    EHLLAPIWait = iRc
End Function


'***********************************************************************
'
' EHLLAPIStartup                    This function is used to initialize
'                                   the WinHLLAPI interface. This call
'                                   should be made when the main form
'                                   loads.
'
'   Return: 0 - Reset performed successfully
'           9 - System Error - DLL probably not loaded
'
'***********************************************************************
'
Function EHLLAPIStartup() As Integer
   Dim startupInfo As WHLLAPIDATA

   iRc = WinHLLAPIStartup(257, startupInfo)

   EHLLAPIStartup = iRc
End Function
'***********************************************************************
'
' EHLLAPICleanup                    This function is used to deinitialize
'                                   the WinHLLAPI interface. This call
'                                   should be made upon the main form
'                                   Unload.
'
'   Return: 0 - Cleanup performed successfully
'
'***********************************************************************
'
Function EHLLAPICleanup() As Integer

   WinHLLAPICleanup

'   EHLLAPIReset = 0
End Function

