Attribute VB_Name = "VBPCSAPI1"
Declare Function pcsQueryEmulatorStatus Lib "PCSAPI32.DLL" (ByVal SessionID As Integer) As Integer
Declare Function pcsQueryWorkstationProfile Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, ByVal buffer As String) As Integer
Declare Function pcsStartSession Lib "PCSAPI32.DLL" (ByVal buffer As String, ByVal SessionID As Integer, ByVal CmdShow As Integer) As Integer
Declare Function pcsStopSession Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, ByVal SaveProfile As Integer) As Integer
Declare Function pcsConnectSession Lib "PCSAPI32.DLL" (ByVal SessionID As Integer) As Integer
Declare Function pcsDisconnectSession Lib "PCSAPI32.DLL" (ByVal SessionID As Integer) As Integer
Declare Function GetVersion Lib "KERNEL32.DLL" () As Long
Const PCS_MAX_FACE_NAME_LENGTH = 32
  Type PgConfType
  nFlags As Long
  nCPI As Long
  nLPI As Long
  szFaceName As String * PCS_MAX_FACE_NAME_LENGTH
  nFontSize As Integer
  nMPL As Integer
  nMPP As Integer
  reserved1 As Integer
  reserved2(2) As Long
 End Type
Declare Function pcsGetPageSettings Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, PgConfData As PgConfType, ErrorNo As Long) As Long
Declare Function pcsRestorePageDefaults Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, ByVal flags As Long) As Long
Declare Function pcsSetPageSettings Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, PgConfData As PgConfType, ErrorNo As Long) As Long

'Printer info structure
Type PrintInfo
   nFlags As Long
   nBufSize As Long
   nSizeNeeded As Long
   bPromptDialog As Long
   bPDTMode As Long
   lpPDTFile As Long
   nPrtMode As Long
   lpPrtToDskAppFile As Long
   lpPrtToDskSepFile As Long
   lpPrinterName As Long
   reserved(2) As Long          'reserved for future. MUST be set to NULL
End Type
Declare Function pcsSetPrinterSettings Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, ByRef PrtConfData As PrintInfo, ErrorNo As Long) As Long
Declare Function pcsGetPrinterSettings Lib "PCSAPI32.DLL" (ByVal SessionID As Integer, ByRef PrtConfData As PrintInfo, ErrorNo As Long) As Long

Global LogData$(0 To 99)
Global LogTop           As Integer
Global LogEnd           As Integer
Global Const MAXLOGNUM = 99

Global MSG_SAMPLE_PROG As String
Global MSG_NO_SESSIONID As String
Global MSG_NO_PROFILENAME As String
Global MSG_SESSION_NOTSTARTED As String
Global MSG_INVALID_SESSIONID As String
Global MSG_ACTIVE_SESSIONID As String
Global MSG_PROFILE_ERROR As String
Global MSG_SYSTEM_ERROR As String

Global Const SESSION_STARTED = 1
Global Const SESSION_ONLINE = 2
Global Const SESSION_API_ENABLED = 4

Global Const SW_HIDE = 0
Global Const SW_MINIMIZE = 6
Global Const SW_RESTORE = 9
Global Const SW_SHOW = 5
Global Const SW_SHOWMAXIMIZED = 3
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMINNOACTIVE = 7
Global Const SW_SHOWNA = 8
Global Const SW_SHOWNOACTIVATE = 4
Global Const SW_SHOWNORMAL = 1

Global Const SS_SAVE_AS_PROFILE = 0
Global Const SS_SAVE_ON_EXIT = 1
Global Const SS_NOSAVE_ON_EXIT = 2



Function SZStr$(s As String)
' Convert variant-string-type (ASCIIZ)
' To string-type (BASIC $-type)
  l = Len(s)
  If l > 0 Then
    For i = 1 To l
      If Mid(s, i, 1) = Chr(0) Then
        Exit For
      End If
    Next
    SZStr$ = Left$(s, i - 1)
  Else
    SZStr$ = ""
  End If
End Function

Sub UpdateLog()
    temp$ = ""
    If LogTop > LogEnd Then
       For i% = LogTop To MAXLOGNUM
          temp$ = temp$ + LogData$(i%)
       Next
       For i% = 0 To LogEnd
          temp$ = temp$ + LogData$(i%)
       Next
    ElseIf LogTop < LogEnd Then
       For i% = LogTop To LogEnd
          temp$ = temp$ + LogData(i%)
       Next
    Else
       temp$ = LogData(i%)
    End If
    FormMain.FunctionLog.Text = temp$
    
End Sub

Sub UpdateLogPointer()
    LogEnd = LogEnd + 1
    If LogEnd = MAXLOGNUM + 1 Then
       LogEnd = 0
    End If

    If LogTop = LogEnd Then
       LogTop = LogTop + 1
       If LogTop = MAXLOGNUM + 1 Then
          LogTop = 0
       End If
    End If
End Sub

Public Sub AdjustForNT351(FormToAdjust As Form)
  Dim VersionInfo As Long
  
  VersionInfo = GetVersion()
  
  If ((VersionInfo And &HFF&) = 3) And ((VersionInfo And &H80000000) = 0) Then
  
    For Each IndexControl In FormToAdjust.Controls()
      If TypeOf IndexControl Is TextBox Then
        If IndexControl.ScrollBars = 1 Then ' if Horizontal ScrollBar
          IndexControl.Height = IndexControl.Height + 120 ' Flat
          IndexControl.Top = IndexControl.Top - 30 ' Flat
        End If
      End If
    Next IndexControl
  
  End If
End Sub


