//---------------------------------------------------------------------------
// ClassExplorer Pro generated header file
// Created by Jean-Marc on 24.12.2003, 10:02:15
//---------------------------------------------------------------------------
#ifndef LdriverXH
#define LdriverXH
#include <classes.hpp>
class TDLPortIOX;
class TDLPrinterPortIOX;
typedef unsigned char UCHAR;    // BYTE
typedef unsigned short USHORT;  // WORD
typedef unsigned long ULONG;    // DWORD

typedef short (__stdcall *TDlPortReadPortUchar)(int Port);
typedef short (__stdcall *TDlPortReadPortUshort)(int Port);
typedef int (__stdcall *TDlPortReadPortUlong)(int Port);

typedef void (__stdcall *TDlPortWritePortUchar)(int Port, short Value);
typedef void (__stdcall *TDlPortWritePortUshort)(int Port, short Value);
typedef void (__stdcall *TDlPortWritePortUlong)(int Port, int Value);

typedef void (__stdcall *TDlPortReadPortBufferUchar)(int Port, short *Buffer, int Count);
typedef void (__stdcall *TDlPortReadPortBufferUshort)(int Port, int *Buffer, int Count);
typedef void (__stdcall *TDlPortReadPortBufferUlong)(int Port, int *Buffer, int Count);

typedef void (__stdcall *TDlPortWritePortBufferUchar)(int Port, short *Buffer, int Count);
typedef void (__stdcall *TDlPortWritePortBufferUshort)(int Port, int *Buffer, int Count);
typedef void (__stdcall *TDlPortWritePortBufferUlong)(int Port, int *Buffer, int Count);

//---------------------------------------------------------------------------
// Data Types
//---------------------------------------------------------------------------

// Specifies the type of read or write in a TPortCommand
typedef enum {tmReadByte,  tmReadWord,  tmReadDWord,
              tmWriteByte, tmWriteWord, tmWriteDWord} TMode;


// Specifies the data required to do a block
// read/write of an array of port records.
// Extends the model TVicHW32/TVicPort uses
typedef struct
{
   USHORT PortAddr;    // The address of the port to read/write
   union             // The data to read/write
   {
      UCHAR  Byte;
      USHORT  Word;
      DWORD DWord;
   } PortData;
   TMode PortMode;   // The mode of reading/writing
} TPortCommand;


// Standard TVicHW32/TVicPort PortRec for compatibility
typedef struct
{
   USHORT PortAddr;
   UCHAR PortData;
   bool fWrite;
} TPortRec;


const MAX_LPT_PORTS = 8;

//---------------------------------------------------------------------------
class PACKAGE TLdriverX {
   friend class TDLPortIOX;
   friend class TDLPrinterPortIOX;
private:
   bool FActiveHW;     // Is the DLL loaded?
   bool FHardAccess;   // Not used: for compatibility only
   bool FRunningWinNT; // True when we're running Windows NT
   bool FRunningWin2K;  // True when we're running Windows 2K Or Xp
   bool FRunningW95;   // True when we're running Windows 9x
   HINSTANCE FDLLInst; // For use with DLL
   SC_HANDLE hSCMan;   // For use with WinNT Service Control Manager

   AnsiString FDriverPath; // Full path of WinNT driver
   AnsiString FDLLPath;    // Full path of DriverLINX DLL
   AnsiString FLastError;  // Last error which occurred in Open/CloseDriver()
    // Used for the Windows NT version only
   bool FDrvPrevInst;   // DriverLINX driver already installed?
   bool FDrvPrevStart;

   char FLPTNumber;    // Current number of the printer port, default=1
   int FLPTBase;      // The address of the current printer port (faster)

   char  FLPTCount;     // Number of LPT ports on the system

   // List of port addresses installed on the system
   short FLPTAddress[MAX_LPT_PORTS+1];

    // Pointers to the functions within the DLL
   TDlPortReadPortUchar  DlReadByte;
   TDlPortReadPortUshort DlReadWord;
   TDlPortReadPortUlong  DlReadDWord;

   TDlPortWritePortUchar  DlWriteByte;
   TDlPortWritePortUshort DlWriteWord;
   TDlPortWritePortUlong  DlWriteDWord;

   TDlPortReadPortBufferUchar  DlReadBufferByte;
   TDlPortReadPortBufferUshort DlReadBufferWord;
   TDlPortReadPortBufferUlong  DlReadBufferDWord;

   TDlPortWritePortBufferUchar  DlWriteBufferByte;
   TDlPortWritePortBufferUshort DlWriteBufferWord;
   TDlPortWritePortBufferUlong  DlWriteBufferDWord;
   // Connects and disconnects to the WinNT Service Control Manager
   bool __fastcall ConnectSCM();
   void __fastcall DisconnectSCM();
    // Installs, starts, stops and removes the WinNT kernel mode driver
   bool __fastcall DriverInstall();
   bool __fastcall DriverStart();
   bool __fastcall DriverStop();
   bool __fastcall DriverRemove();  // DriverLINX driver already running?
   void __fastcall DetectPorts();
   void __fastcall DetectPorts9x();
   void __fastcall DetectPortsNT();
   void __fastcall DetectPorts2k();
   void __fastcall OpenDriver();
   void __fastcall CloseDriver();
   void __fastcall Clean(HKEY OpenKey, char** Buffer, long Count);
protected:
   bool __fastcall IsLoaded()
      { return FActiveHW; }
public:
        __fastcall TLdriverX();
        __fastcall ~TLdriverX();
};

//---------------------------------------------------------------------------
#endif
