//ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
//Û                                                      Û
//Û     Virtual Pascal Runtime Library.  Version 2.1     Û
//Û     Windows Print API interface unit                 Û
//Û     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÛ
//Û     Copyright (C) 1999-2000 vpascal.com              Û
//Û                                                      Û
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

unit WinSpool;

{&AlignRec+,StdCall+,SmartLink+,OrgName+,Use32-}

interface

uses
  Windows;

type
  PPrinterInfo1 = ^TPrinterInfo1;
  TPrinterInfo1 = record
    Flags:        DWord;
    pDescription: PChar;
    pName:        PChar;
    pComment:     PChar;
  end;

  PPrinterInfo2 = ^TPrinterInfo2;
  TPrinterInfo2 = record
    pServerName:     PChar;
    pPrinterName:    PChar;
    pShareName:      PChar;
    pPortName:       PChar;
    pDriverName:     PChar;
    pComment:        PChar;
    pLocation:       PChar;
    pDevMode:        PDeviceMode;
    pSepFile:        PChar;
    pPrintProcessor: PChar;
    pDatatype:       PChar;
    pParameters:     PChar;
    pSecurityDescriptor: PSecurityDescriptor;
    Attributes:      DWord;
    Priority:        DWord;
    DefaultPriority: DWord;
    StartTime:       DWord;
    UntilTime:       DWord;
    Status:          DWord;
    cJobs:           DWord;
    AveragePPM:      DWord;
  end;

  PPrinterInfo3 = ^TPrinterInfo3;
  TPrinterInfo3 = record
    pSecurityDescriptor: PSecurityDescriptor;
  end;

  PPrinterInfo4 = ^TPrinterInfo4;
  TPrinterInfo4 = record
    pPrinterName: PChar;
    pServerName:  PChar;
    Attributes:   DWord;
  end;

  PPrinterInfo5 = ^TPrinterInfo5;
  TPrinterInfo5 = record
    pPrinterName: PChar;
    pPortName:    PChar;
    Attributes:   DWord;
    DeviceNotSelectedTimeout: DWord;
    TransmissionRetryTimeout: DWord;
  end;

  PPrinterInfo6 = ^TPrinterInfo6;
  TPrinterInfo6 = record
    dwStatus: DWord;
  end;

  PPrinterInfo7 = ^TPrinterInfo7;
  TPrinterInfo7 = record
    pszObjectGUID: PChar;
    dwAction:      DWord;
  end;

const
  dsprint_Publish               = 1;
  dsprint_Update                = 2;
  dsprint_Unpublish             = 3;

  printer_Control_Pause         = 1;
  printer_Control_Resume        = 2;
  printer_Control_Purge         = 3;
  printer_Control_Set_Status    = 4;

  printer_Status_Paused         = $00000001;
  printer_Status_Error          = $00000002;
  printer_Status_Pending_Deletion = $00000004;
  printer_Status_Paper_Jam      = $00000008;
  printer_Status_Paper_Out      = $00000010;
  printer_Status_Manual_Feed    = $00000020;
  printer_Status_Paper_Problem  = $00000040;
  printer_Status_Offline        = $00000080;
  printer_Status_IO_Active      = $00000100;
  printer_Status_Busy           = $00000200;
  printer_Status_Printing       = $00000400;
  printer_Status_Output_Bin_Full = $00000800;
  printer_Status_Not_Available  = $00001000;
  printer_Status_Waiting        = $00002000;
  printer_Status_Processing     = $00004000;
  printer_Status_Initializing   = $00008000;
  printer_Status_Warming_Up     = $00010000;
  printer_Status_Toner_Low      = $00020000;
  printer_Status_No_Toner       = $00040000;
  printer_Status_Page_Punt      = $00080000;
  printer_Status_User_Intervention = $00100000;
  printer_Status_Out_Of_Memory  = $00200000;
  printer_Status_Door_Open      = $00400000;
  printer_Status_Server_Unknown = $00800000;
  printer_Status_Power_Save     = $01000000;

  printer_Attribute_Queued      = $00000001;
  printer_Attribute_Direct      = $00000002;
  printer_Attribute_Default     = $00000004;
  printer_Attribute_Shared      = $00000008;
  printer_Attribute_Network     = $00000010;
  printer_Attribute_Hidden      = $00000020;
  printer_Attribute_Local       = $00000040;

  printer_Attribute_Enable_Devq = $00000080;
  printer_Attribute_KeepprintedjobS = $00000100;
  printer_Attribute_Do_Complete_First = $00000200;

  printer_Attribute_Work_Offline = $00000400;
  printer_Attribute_Enable_Bidi = $00000800;
  printer_Attribute_Raw_Only    = $00001000;
  printer_Attribute_Published   = $00002000;


  no_Priority                   = 0;
  max_Priority                  = 99;
  min_Priority                  = 1;
  def_Priority                  = 1;

type
  PJobInfo1 = ^TJobInfo1;
  TJobInfo1 = record
    JobId:        DWord;
    pPrinterName: PChar;
    pMachineName: PChar;
    pUserName:    PChar;
    pDocument:    PChar;
    pDatatype:    PChar;
    pStatus:      PChar;
    Status:       DWord;
    Priority:     DWord;
    Position:     DWord;
    TotalPages:   DWord;
    PagesPrinted: DWord;
    Submitted:    TSystemTime;
  end;

  PJobInfo2 = ^TJobInfo2;
  TJobInfo2 = record
    JobId:                DWord;
    pPrinterName:         PChar;
    pMachineName:         PChar;
    pUserName:            PChar;
    pDocument:            PChar;
    pNotifyName:          PChar;
    pDatatype:            PChar;
    pPrintProcessor:      PChar;
    pParameters:          PChar;
    pDriverName:          PChar;
    pDevMode:             PDeviceMode;
    pStatus:              PChar;
    PSecurityDescriptor:  pSecurityDescriptor;
    Status:               DWord;
    Priority:             DWord;
    Position:             DWord;
    StartTime:            DWord;
    UntilTime:            DWord;
    TotalPages:           DWord;
    Size:                 DWord;
    Submitted:            TSystemTime;  // Time the job was spooled
    Time:                 DWord;        // How many seconds the job has been printing
    PagesPrinted:         DWord;
  end;

  PJobInfo3 = ^TJobInfo3;
  TJobInfo3 = record
    JobId:     DWord;
    NextJobId: DWord;
    Reserved:  DWord;
  end;

const
  job_Control_Pause             = 1;
  job_Control_Resume            = 2;
  job_Control_Cancel            = 3;
  job_Control_Restart           = 4;
  job_Control_Delete            = 5;
  job_Control_Sent_To_Printer   = 6;
  job_Control_Last_Page_Ejected = 7;

  job_Status_Paused             = $00000001;
  job_Status_Error              = $00000002;
  job_Status_Deleting           = $00000004;
  job_Status_Spooling           = $00000008;
  job_Status_Printing           = $00000010;
  job_Status_Offline            = $00000020;
  job_Status_Paperout           = $00000040;
  job_Status_Printed            = $00000080;
  job_Status_Deleted            = $00000100;
  job_Status_Blocked_Devq       = $00000200;
  job_Status_User_Intervention  = $00000400;
  job_Status_Restart            = $00000800;

  job_Position_Unspecified      = 0;

type
  PAddJobInfo1 = ^TAddJobInfo1;
  TAddJobInfo1 = record
    Path:  PChar;
    JobId: DWord;
  end;

  PDriverInfo1 = ^TDriverInfo1;
  TDriverInfo1 = record
    pName: PChar;              // QMS 810
  end;

  PDriverInfo2 = ^TDriverInfo2;
  TDriverInfo2 = record
    cVersion:     DWord;
    pName:        PChar;  // QMS 810
    pEnvironment: PChar;  // Win32 x86
    pDriverPath:  PChar;  // c:\drivers\pscript.dll
    pDataFile:    PChar;  // c:\drivers\QMS810.PPD
    pConfigFile:  PChar;  // c:\drivers\PSCRPTUI.DLL
  end;

  PDriverInfo3 = ^TDriverInfo3;
  TDriverInfo3 = record
    cVersion:         DWord;
    pName:            PChar; // QMS 810
    pEnvironment:     PChar; // Win32 x86
    pDriverPath:      PChar; // c:\drivers\pscript.dll
    pDataFile:        PChar; // c:\drivers\QMS810.PPD
    pConfigFile:      PChar; // c:\drivers\PSCRPTUI.DLL
    pHelpFile:        PChar; // c:\drivers\PSCRPTUI.HLP
    pDependentFiles:  PChar; // PSCRIPT.DLL\0QMS810.PPD\0PSCRIPTUI.DLL\0PSCRIPTUI.HLP\0PSTEST.TXT\0\0
    pMonitorName:     PChar; // "PJL monitor"
    pDefaultDataType: PChar; // "EMF"
  end;

const
// FLAGS for DeletePrinterDriverEx.
  dpd_Delete_Unused_Files       = $00000001;
  dpd_Delete_Specific_Version   = $00000002;
  dpd_Delete_All_Files          = $00000004;

// FLAGS for AddPrinterDriverEx.
  apd_Strict_Upgrade            = $00000001;
  apd_Strict_DowngradE          = $00000002;
  apd_Copy_All_Files            = $00000004;
  apd_Copy_New_Files            = $00000008;

type
  PDocInfo1 = ^TDocInfo1;
  TDocInfo1 = record
    pDocName:    PChar;
    pOutputFile: PChar;
    pDatatype:   PChar;
  end;

  PFormInfo1 = ^TFormInfo1;
  TFormInfo1 = record
    Flags:         DWord;
    pName:         PChar;
    Size:          TSize;
    ImageableArea: TRect;
  end;

  PDocInfo2 = ^TDocInfo2;
  TDocInfo2 = record
    pDocName:    PChar;
    pOutputFile: PChar;
    pDatatype:   PChar;
    dwMode:      DWord;
    JobId:       DWord;
  end;

const
  di_Channel                    = 1;    // start direct read/write channel,
  di_Read_Spool_Job             = 3;
  form_User                     = $00000000;
  form_Builtin                  = $00000001;
  form_Printer                  = $00000002;

type
  PPrintProcessorInfo1 = ^TPrintProcessorInfo1;
  TPrintProcessorInfo1 = record
    pName: PChar;
  end;

  PPrintProcessorCaps1 = ^TPrintProcessorCaps1;
  TPrintProcessorCaps1 = record
    dwLevel:          DWord;
    dwNupOptions:     DWord;
    dwPageOrderFlags: DWord;
    dwNumberOfCopies: DWord;
  end;

  PPortInfo1 = ^TPortInfo1;
  TPortInfo1 = record
    pName: PChar;
  end;

  PPortInfo2 = ^TPortInfo2;
  TPortInfo2 = record
    pPortName:    PChar;
    pMonitorName: PChar;
    pDescription: PChar;
    fPortType:    DWord;
    Reserved:     DWord;
  end;

const
  port_Type_Write               = $0001;
  port_Type_Read                = $0002;
  port_Type_Redirected          = $0004;
  port_Type_Net_Attached        = $0008;

type
  PPortInfo3 = ^TPortInfo3;
  TPortInfo3 = record
    dwStatus:   DWord;
    pszStatus:  PChar;
    dwSeverity: DWord;
  end;

const
  port_Status_Type_Error        = 1;
  port_Status_Type_Warning      = 2;
  port_Status_Type_Info         = 3;

  port_Status_Offline           = 1;
  port_Status_Paper_Jam         = 2;
  port_Status_Paper_Out         = 3;
  port_Status_Output_Bin_Full   = 4;
  port_Status_Paper_Problem     = 5;
  port_Status_No_Toner          = 6;
  port_Status_Door_Open         = 7;
  port_Status_User_Intervention = 8;
  port_Status_Out_Of_Memory     = 9;

  port_Status_Toner_Low         = 10;

  port_Status_Warming_Up        = 11;
  port_Status_Power_Save        = 12;

type
  PMonitorInfo1 = ^TMonitorInfo1;
  TMonitorInfo1 = record
    pName: PChar;
  end;

  PMonitorInfo2 = ^TMonitorInfo2;
  TMonitorInfo2 = record
    pName:        PChar;
    pEnvironment: PChar;
    pDLLName:     PChar;
  end;

  PDataTypesInfo1 = ^TDataTypesInfo1;
  TDataTypesInfo1 = record
    pName: PChar;
  end;

  PPrinterDefaults = ^TPrinterDefaults;
  TPrinterDefaults = record
    pDatatype:     PChar;
    pDevMode:      PDeviceMode;
    DesiredAccess: ACCESS_MASK;
  end;

  PPrinterEnumValues = ^TPrinterEnumValues;
  TPrinterEnumValues = record
    pValueName:  PChar;
    cbValueName: DWord;
    dwType:      DWord;
    pData:       Pointer;
    cbData:      DWord;
  end;

function EnumPrinters(Flags: DWord; Name: PChar; Level: DWord; pPrinterEnum: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;

const
  printer_Enum_Default          = $00000001;
  printer_Enum_Local            = $00000002;
  printer_Enum_Connections      = $00000004;
  printer_Enum_Favorite         = $00000004;
  printer_Enum_Name             = $00000008;
  printer_Enum_Remote           = $00000010;
  printer_Enum_Shared           = $00000020;
  printer_Enum_Network          = $00000040;

  printer_Enum_Expand           = $00004000;
  printer_Enum_Container        = $00008000;

  printer_Enum_Iconmask         = $00ff0000;
  printer_Enum_Icon1            = $00010000;
  printer_Enum_Icon2            = $00020000;
  printer_Enum_Icon3            = $00040000;
  printer_Enum_Icon4            = $00080000;
  printer_Enum_Icon5            = $00100000;
  printer_Enum_Icon6            = $00200000;
  printer_Enum_Icon7            = $00400000;
  printer_Enum_Icon8            = $00800000;

function OpenPrinter(pPrinterName: PChar; var phPrinter: THandle; pDefault: PPrinterDefaults): Bool;
function ResetPrinter(hPrinter: THandle; pDefault: PPrinterDefaults): Bool;
function SetJob(hPrinter: THandle; JobId,Level: DWord; pJob: Pointer; Command: DWord): Bool;
function GetJob(hPrinter: THandle; JobId,Level: DWord; pJob: Pointer; cbBuf: DWord; pcbNeeded: PDWord): Bool;
function EnumJobs(hPrinter: THandle; FirstJob,NoJobs,Level: DWord; pJob: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function AddPrinter(pName: PChar; Level: DWord; pPrinter: Pointer): THandle;
function DeletePrinter(hPrinter: THandle): Bool;
function SetPrinter(hPrinter: THandle; Level: DWord; pPrinter: Pointer; Command: DWord): Bool;
function GetPrinter(hPrinter: THandle; Level: DWord; pPrinter: Pointer; cbBuf: DWord; pcbNeeded: PDWord): Bool;
function AddPrinterDriver(pName: PChar; Level: DWord; pDriverInfo: Pointer): Bool;
function AddPrinterDriverEx(pName: PChar; Level: DWord; pDriverInfo: Pointer; dwFileCopyFlags: DWord): Bool;
function EnumPrinterDrivers(pName,pEnvironment: PChar; Level: DWord; pDriverInfo: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function GetPrinterDriver(hPrinter: THandle; pEnvironment: PChar; Level: DWord; pDriverInfo: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function GetPrinterDriverDirectory(pName,pEnvironment: PChar; Level: DWord; pDriverDirectory: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function DeletePrinterDriver(pName,pEnvironment,pDriverName: PChar): Bool;
function DeletePrinterDriverEx(pName,pEnvironment,pDriverName: PChar; dwDeleteFlag,dwVersionFlag: DWord): Bool;
function AddPerMachineConnection(pServer,pPrinterName,pPrintServer,pProvider: PChar): Bool;
function DeletePerMachineConnection(pServer,pPrinterName: PChar): Bool;
function EnumPerMachineConnections(pServer: PChar; pPrinterEnum: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function AddPrintProcessor(pName,pEnvironment,pPathName,pPrintProcessorName: PChar): Bool;
function EnumPrintProcessors(pName,pEnvironment: PChar; Level: DWord; pPrintProcessorInfo: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function GetPrintProcessorDirectory(pName, pEnvironment: PChar; Level: DWord; pPrintProcessorInfo: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function EnumPrintProcessorDatatypes(pName, pPrintProcessorName: PChar; Level: DWord; pDatatypes: Pointer; cbBuf: DWord; var pcbNeeded, pcReturned: DWord): Bool;
function DeletePrintProcessor(pName, pEnvironment, pPrintProcessorName: PChar): Bool;
function StartDocPrinter(hPrinter: THandle; Level: DWord; pDocInfo: Pointer): DWord;
function StartPagePrinter(hPrinter: THandle): Bool;
function WritePrinter(hPrinter: THandle; pBuf: Pointer; cbBuf: DWord; var pcWritten: DWord): Bool;
function EndPagePrinter(hPrinter: THandle): Bool;
function AbortPrinter(hPrinter: THandle): Bool;
function ReadPrinter(hPrinter: THandle; pBuf: Pointer; cbBuf: DWord; var pNoBytesRead: DWord): Bool;
function EndDocPrinter(hPrinter: THandle): Bool;
function AddJob(hPrinter: THandle; Level: DWord; pData: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function ScheduleJob(hPrinter: THandle; JobId: DWord): Bool;
function PrinterProperties(hWnd: HWnd; hPrinter: THandle): Bool;
function DocumentProperties(hWnd: HWnd; hPrinter: THandle; pDeviceName: PChar; const pDevModeOutput: TDeviceMode; var pDevModeInput: TDeviceMode; fMode: DWord): Longint;
function AdvancedDocumentProperties(hWnd: HWnd; hPrinter: THandle; pDeviceName: PChar; pDevModeOutput, pDevModeInput: PDeviceMode): Longint;
function GetPrinterData(hPrinter: THandle; pValueName: PChar; pType: PDWord; pData: Pointer; nSize: DWord; var pcbNeeded: DWord): DWord;
function GetPrinterDataEx(hPrinter: THandle; pKeyName,pValueName: PChar; pType: PDWord; pData: Pointer; nSize: DWord; var pcbNeeded: DWord): DWord;
function EnumPrinterData(hPrinter: THandle; dwIndex: DWord; pValueName: PChar; cbValueName: DWord; var pcbValueName, pType: DWord; pData: PByte; cbData: DWord; pcbData: PDWord): DWord;
function EnumPrinterDataEx(hPrinter: THandle; pKeyName: PChar; pEnumValues: Pointer; cbEnumValues: DWord; var pcbEnumValues,pnEnumValues: DWord): DWord;
function EnumPrinterKey(hPrinter: THandle; pKeyName,pSubkey: PChar; cbSubkey: DWord; pcbSubkey: PDWord): DWord;
function SetPrinterData(hPrinter: THandle; pValueName: PChar; dwType: DWord; pData: Pointer; cbData: DWord): DWord;
function SetPrinterDataEx(hPrinter: THandle; pKeyName,pValueName: PChar; dwType: DWord; pData: Pointer; cbData: DWord): DWord;
function DeletePrinterData(hPrinter: THandle; pValueName: PChar): DWord;
function DeletePrinterDataEx(hPrinter: THandle; pKeyName,pValueName: PChar): DWord;
function DeletePrinterKey(hPrinter: THandle; pKeyName: PChar): DWord;

const
  PRINTER_NOTIFY_TYPE           = $00;
  JOB_NOTIFY_TYPE               = $01;

  printer_Notify_Field_Server_Name         = $00;
  printer_Notify_Field_Printer_Name        = $01;
  printer_Notify_Field_Share_Name          = $02;
  printer_Notify_Field_Port_Name           = $03;
  printer_Notify_Field_Driver_Name         = $04;
  printer_Notify_Field_Comment             = $05;
  printer_Notify_Field_Location            = $06;
  printer_Notify_Field_Devmode             = $07;
  printer_Notify_Field_Sepfile             = $08;
  printer_Notify_Field_Print_Processor     = $09;
  printer_Notify_Field_Parameters          = $0A;
  printer_Notify_Field_Datatype            = $0B;
  printer_Notify_Field_Security_Descriptor = $0C;
  printer_Notify_Field_Attributes          = $0D;
  printer_Notify_Field_Priority            = $0E;
  printer_Notify_Field_Default_Priority    = $0F;
  printer_Notify_Field_Start_Time          = $10;
  printer_Notify_Field_Until_Time          = $11;
  printer_Notify_Field_Status              = $12;
  printer_Notify_Field_Status_String       = $13;
  printer_Notify_Field_Cjobs               = $14;
  printer_Notify_Field_Average_Ppm         = $15;
  printer_Notify_Field_Total_Pages         = $16;
  printer_Notify_Field_Pages_Printed       = $17;
  printer_Notify_Field_Total_Bytes         = $18;
  printer_Notify_Field_Bytes_Printed       = $19;
  printer_Notify_Field_Object_Guid         = $1A;

  job_Notify_Field_Printer_Name            = $00;
  job_Notify_Field_Machine_Name            = $01;
  job_Notify_Field_Port_Name               = $02;
  job_Notify_Field_User_Name               = $03;
  job_Notify_Field_Notify_Name             = $04;
  job_Notify_Field_Datatype                = $05;
  job_Notify_Field_Print_Processor         = $06;
  job_Notify_Field_Parameters              = $07;
  job_Notify_Field_Driver_Name             = $08;
  job_Notify_Field_Devmode                 = $09;
  job_Notify_Field_Status                  = $0A;
  job_Notify_Field_Status_String           = $0B;
  job_Notify_Field_Security_Descriptor     = $0C;
  job_Notify_Field_Document                = $0D;
  job_Notify_Field_Priority                = $0E;
  job_Notify_Field_Position                = $0F;
  job_Notify_Field_Submitted               = $10;
  job_Notify_Field_Start_Time              = $11;
  job_Notify_Field_Until_Time              = $12;
  job_Notify_Field_Time                    = $13;
  job_Notify_Field_Total_Pages             = $14;
  job_Notify_Field_Pages_Printed           = $15;
  job_Notify_Field_Total_Bytes             = $16;
  job_Notify_Field_Bytes_Printed           = $17;


type
  PPrinterNotifyOptionsType = ^TPrinterNotifyOptionsType;
  TPrinterNotifyOptionsType = record
    wType:     Word;
    Reserved0: Word;
    Reserved1: DWord;
    Reserved2: DWord;
    Count:     DWord;
    pFields:   PWord;
  end;


const
  printer_Notify_Options_Refresh = $01;

type
  PPrinterNotifyOptions = ^TPrinterNotifyOptions;
  TPrinterNotifyOptions = record
    Version: DWord;
    Flags:   DWord;
    Count:   DWord;
    pTypes:  PPrinterNotifyOptionsType;
  end;

const
  printer_Notify_Info_Discarded = $01;

type
  PPrinterNotifyInfoData = ^TPrinterNotifyInfoData;
  TPrinterNotifyInfoData = record
    wType:      Word;
    Field:      Word;
    Reserved:   DWord;
    Id:         DWord;
    NotifyData: record
      case Integer of
        0: (adwData: array[0..1] of DWord);
        1: (Data: record
              cbBuf: DWord;
              pBuf:  Pointer;
            end);
    end;
  end;

  PPrinterNotifyInfo = ^TPrinterNotifyInfo;
  TPrinterNotifyInfo = record
    Version: DWord;
    Flags:   DWord;
    Count:   DWord;
    aData: array[0..0] of TPrinterNotifyInfoData;
  end;

function WaitForPrinterChange(hPrinter: THandle; Flags: DWord): DWord;
function FindFirstPrinterChangeNotification(hPrinter: THandle; fdwFlags,fdwOptions: DWord; pPrinterNotifyOptions: Pointer): THandle;
function FindNextPrinterChangeNotification(hChange: THandle; var pdwChange: DWord; pvReserved: Pointer; var ppPrinterNotifyInfo: Pointer): Bool;
function FreePrinterNotifyInfo(pPrinterNotifyInfo: PPrinterNotifyInfo): Bool;
function FindClosePrinterChangeNotification(hChange: THandle): Bool;

const
  printer_Change_Add_Printer    = $00000001;
  printer_Change_Set_Printer    = $00000002;
  printer_Change_Delete_Printer = $00000004;
  printer_Change_Failed_Connection_Printer = $00000008;
  printer_Change_Printer        = $000000FF;
  printer_Change_Add_Job        = $00000100;
  printer_Change_Set_Job        = $00000200;
  printer_Change_Delete_Job     = $00000400;
  printer_Change_Write_Job      = $00000800;
  printer_Change_Job            = $0000FF00;
  printer_Change_Add_Form       = $00010000;
  printer_Change_Set_Form       = $00020000;
  printer_Change_Delete_Form    = $00040000;
  printer_Change_Form           = $00070000;
  printer_Change_Add_Port       = $00100000;
  printer_Change_Configure_Port = $00200000;
  printer_Change_Delete_Port    = $00400000;
  printer_Change_Port           = $00700000;
  printer_Change_Add_Print_Processor = $01000000;
  printer_Change_Delete_Print_Processor = $04000000;
  printer_Change_Print_Processor = $07000000;
  printer_Change_Add_Printer_Driver = $10000000;
  printer_Change_Set_Printer_Driver = $20000000;
  printer_Change_Delete_Printer_Driver = $40000000;
  printer_Change_Printer_Driver = $70000000;
  printer_Change_Timeout        = $80000000;
  printer_Change_All            = $7777FFFF;

function PrinterMessageBox(hPrinter: THandle; Error: DWord; hWnd: HWnd; pText,pCaption: PChar; dwType: DWord): DWord;

const
  printer_Error_Information     = $80000000;
  printer_Error_Warning         = $40000000;
  printer_Error_Severe          = $20000000;

  printer_Error_Outofpaper      = $00000001;
  printer_Error_Jam             = $00000002;
  printer_Error_Outoftoner      = $00000004;

function ClosePrinter(hPrinter: THandle): Bool;
function AddForm(hPrinter: THandle; Level: DWord; pForm: Pointer): Bool;
function DeleteForm(hPrinter: THandle; pFormName: PChar): Bool;
function GetForm(hPrinter: THandle; pFormName: PChar; Level: DWord; pForm: Pointer; cbBuf: DWord; var pcbNeeded: DWord): Bool;
function SetForm(hPrinter: THandle; pFormName: PChar; Level: DWord; pForm: Pointer): Bool;
function EnumForms(hPrinter: THandle; Level: DWord; pForm: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function EnumMonitors(pName: PChar; Level: DWord; pMonitors: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function AddMonitor(pName: PChar; Level: DWord; pMonitors: Pointer): Bool;
function DeleteMonitor(pName, pEnvironment, pMonitorName: PChar): Bool;
function EnumPorts(pName: PChar; Level: DWord; pPorts: Pointer; cbBuf: DWord; var pcbNeeded,pcReturned: DWord): Bool;
function AddPort(pName: PChar; hWnd: HWnd; pMonitorName: PChar): Bool;
function ConfigurePort(pName: PChar; hWnd: HWnd; pPortName: PChar): Bool;
function DeletePort(pName: PChar; hWnd: HWnd; pPortName: PChar): Bool;
function XcvData(hXcv: THandle; pszDataName: PChar{PWideChar}; pInputData: Pointer; cbInputData: DWord; pOutputData: Pointer; cbOutputData: DWord; pcbOutputNeeded,pdwStatus: PDWord): Bool;
function SetPort(pName, pPortName: PChar; dwLevel: DWord; pPortInfo: Pointer): Bool;
function AddPrinterConnection(pName: PChar): Bool;
function DeletePrinterConnection(pName: PChar): Bool;
function ConnectToPrinterDlg(hwnd: HWnd; Flags: DWord): THandle;

type
  PProvidorInfo1 = ^TProvidorInfo1;
  TProvidorInfo1 = record
    pName:        PChar;
    pEnvironment: PChar;
    pDLLName:     PChar;
  end;


function AddPrintProvidor(pName: PChar; level: DWord; pProvidorInfo: Pointer): Bool;
function DeletePrintProvidor(pName,pEnvironment,pPrintProvidorName: PChar): Bool;

// SetPrinterData and GetPrinterData Server Handle Key values

const
  splreg_Default_Spool_Directory            = 'DefaultSpoolDirectory';
  splreg_Port_Thread_Priority_Default       = 'PortThreadPriorityDefault';
  splreg_Port_Thread_Priority               = 'PortThreadPriority';
  splreg_Scheduler_Thread_Priority_Default  = 'SchedulerThreadPriorityDefault';
  splreg_Scheduler_Thread_Priority          = 'SchedulerThreadPriority';
  splreg_Beep_Enabled                       = 'BeepEnabled';
  splreg_Net_Popup                          = 'NetPopup';
  splreg_Event_Log                          = 'EventLog';
  splreg_Major_Version                      = 'MajorVersion';
  splreg_Minor_Version                      = 'MinorVersion';
  splreg_Architecture                       = 'Architecture';
  splreg_Os_Version                         = 'OSVersion';
  splreg_Ds_Present                         = 'DsPresent';

  server_Access_Administer      = $00000001;
  server_Access_Enumerate       = $00000002;

  printer_Access_Administer     = $00000004;
  printer_Access_Use            = $00000008;

  job_Access_Administer         = $00000010;


// Access rights for print servers

  server_All_Access             = standard_Rights_Required or server_Access_Administer or server_Access_Enumerate;
  server_Read                   = standard_Rights_Read or server_Access_Enumerate;
  server_Write                  = standard_Rights_Write or server_Access_Administer or server_Access_Enumerate;
  server_Execute                = standard_Rights_Execute or server_Access_Enumerate;

// Access rights for printers

  printer_All_Access            = standard_Rights_Required or printer_Access_Administer or printer_Access_Use;
  printer_Read                  = standard_Rights_Read or printer_Access_Use;
  printer_Write                 = standard_Rights_Write or printer_Access_Use;
  printer_Execute               = standard_Rights_Execute or printer_Access_Use;

// Access rights for jobs

  job_All_Access                = standard_Rights_Required or job_Access_Administer;
  job_Read                      = standard_Rights_Read or job_Access_Administer;
  job_Write                     = standard_Rights_Write or job_Access_Administer;
  job_Execute                   = standard_Rights_Execute or job_Access_Administer;

// DS Print-Queue property tables

// Predefined Registry Keys used by Set/GetPrinterDataEx
  splds_Spooler_Key             = 'DsSpooler';
  splds_Driver_Key              = 'DsDriver';
  splds_User_Key                = 'DsUser';


// DS Print-Queue properties

  splds_Asset_Number            = 'assetNumber';
  splds_Bytes_Per_Minute        = 'bytesPerMinute';
  splds_Description             = 'description';
  splds_Driver_Name             = 'driverName';
  splds_Driver_Version          = 'driverVersion';
  splds_Location                = 'location';
  splds_Port_Name               = 'portName';
  splds_Print_Attributes        = 'printAttributes';
  splds_Print_Bin_Names         = 'printBinNames';
  splds_Print_Collate           = 'printCollate';
  splds_Print_Color             = 'printColor';
  splds_Print_Duplex_Supported  = 'printDuplexSupported';
  splds_Print_End_Time          = 'printEndTime';
  splds_Printer_Class           = 'printQueue';
  splds_Printer_Name            = 'printerName';
  splds_Print_Keep_Printed_Jobs = 'printKeepPrintedJobs';
  splds_Print_Language          = 'printLanguage';
  splds_Print_Mac_Address       = 'printMACAddress';
  splds_Print_Max_X_Extent      = 'printMaxXExtent';
  splds_Print_Max_Y_Extent      = 'printMaxYExtent';
  splds_Print_Max_Resolution_Supported = 'printMaxResolutionSupported';
  splds_Print_Media_Ready       = 'printMediaReady';
  splds_Print_Media_Supported   = 'printMediaSupported';
  splds_Print_Memory            = 'printMemory';
  splds_Print_Min_X_Extent      = 'printMinXExtent';
  splds_Print_Min_Y_Extent      = 'printMinYExtent';
  splds_Print_Network_Address   = 'printNetworkAddress';
  splds_Print_Notify            = 'printNotify';
  splds_Print_Number_Up         = 'printNumberUp';
  splds_Print_Orientations_Supported = 'printOrientationsSupported';
  splds_Print_Owner             = 'printOwner';
  splds_Print_Rate              = 'printRate';
  splds_Print_Rate_Unit         = 'printRateUnit';
  splds_Print_Separator_File    = 'printSeparatorFile';
  splds_Print_Share_Name        = 'printShareName';
  splds_Print_Spooling          = 'printSpooling';
  splds_Print_Stapling_Supported = 'printStaplingSupported';
  splds_Print_Start_Time        = 'printStartTime';
  splds_Print_Status            = 'printStatus';
  splds_Priority                = 'priority';
  splds_Server_Name             = 'serverName';
  splds_Unc_Name                = 'uNCName';
  splds_Url                     = 'url';
  splds_Version_Number          = 'versionNumber';

//  -- Additional Print-Queue properties --
//
//  These properties are not defined in the default Directory Services Schema,
//  but should be used when extending the Schema so a consistent interface is maintained.

  splds_Printer_Name_Aliases    = 'printerNameAliases'; // MULTI_SZ
  splds_Printer_Locations       = 'printerLocations';   // MULTI_SZ
  splds_Printer_Model           = 'printerModel';       // SZ

  printer_Html_View_Queue       = 0;
  printer_Html_View_PrintProperties = 1;
  printer_Html_View_Install     = 2;
  printer_Html_View_JobProperties = 3;


function SetPrinterHTMLView(hPrinter: THandle; dwView: DWord; lpszPath: PChar): DWord;
function GetPrinterHTMLView(hPrinter: THandle; dwView: DWord; lpszPath: PChar; nSize: DWord; pcbNeeded: PDWord): DWord;
{&OrgName-}
function DeviceCapabilities(pDevice,pPort: PChar; fwCapability: Word; pOutput: PChar; DevMode: PDeviceMode): Integer;
{&OrgName+}

implementation

function EnumPrinters;                  external;
function OpenPrinter;                   external;
function ResetPrinter;                  external;
function SetJob;                        external;
function GetJob;                        external;
function EnumJobs;                      external;
function AddPrinter;                    external;
function DeletePrinter;                 external;
function SetPrinter;                    external;
function GetPrinter;                    external;
function AddPrinterDriver;              external;
function AddPrinterDriverEx;            external;
function EnumPrinterDrivers;            external;
function GetPrinterDriver;              external;
function GetPrinterDriverDirectory;     external;
function DeletePrinterDriver;           external;
function DeletePrinterDriverEx;         external;
function AddPerMachineConnection;       external;
function DeletePerMachineConnection;    external;
function EnumPerMachineConnections;     external;
function AddPrintProcessor;             external;
function EnumPrintProcessors;           external;
function GetPrintProcessorDirectory;    external;
function EnumPrintProcessorDatatypes;   external;
function DeletePrintProcessor;          external;
function StartDocPrinter;               external;
function StartPagePrinter;              external;
function WritePrinter;                  external;
function EndPagePrinter;                external;
function AbortPrinter;                  external;
function ReadPrinter;                   external;
function EndDocPrinter;                 external;
function AddJob;                        external;
function ScheduleJob;                   external;
function PrinterProperties;             external;
function DocumentProperties;            external;
function AdvancedDocumentProperties;    external;
function GetPrinterData;                external;
function GetPrinterDataEx;              external;
function EnumPrinterData;               external;
function EnumPrinterDataEx;             external;
function EnumPrinterKey;                external;
function SetPrinterData;                external;
function SetPrinterDataEx;              external;
function DeletePrinterData;             external;
function DeletePrinterDataEx;           external;
function DeletePrinterKey;              external;
function WaitForPrinterChange;          external;
function FindFirstPrinterChangeNotification; external;
function FindNextPrinterChangeNotification;  external;
function FreePrinterNotifyInfo;         external;
function FindClosePrinterChangeNotification; external;
function PrinterMessageBox;             external;
function ClosePrinter;                  external;
function AddForm;                       external;
function DeleteForm;                    external;
function GetForm;                       external;
function SetForm;                       external;
function EnumForms;                     external;
function EnumMonitors;                  external;
function AddMonitor;                    external;
function DeleteMonitor;                 external;
function EnumPorts;                     external;
function AddPort;                       external;
function ConfigurePort;                 external;
function DeletePort;                    external;
function XcvData;                       external;
function SetPort;                       external;
function AddPrinterConnection;          external;
function DeletePrinterConnection;       external;
function ConnectToPrinterDlg;           external;
function AddPrintProvidor;              external;
function DeletePrintProvidor;           external;
function SetPrinterHTMLView;            external;
function GetPrinterHTMLView;            external;
function DeviceCapabilities;            external;

end.
