ChrisSutcliffe
Programmer
Hello there im trying to create a printer queue monitor using API calls. So far ive been able to list the available printers using APRINTERS() and display the amount of jobs per printer using OPENPRINTER(),CLOSEPRINTER() and ENUMJOBS(). My problem is that i need to display the full information about a print job i.e document name etc, i know i need to include JOB_INFO_STRUCTURE_n somewhere but im unsure how to include this in my code. This is where i have got so far:
**********************************************************************
* Get List of Printers
**********************************************************************
nNoOfPrinters=APRINTERS(aPrinterList)
FOR n = 1 TO nNoOfPrinters
**********************************************************************
* Declare the API functions
**********************************************************************
DECLARE Integer OpenPrinter in WinSpool.Drv as WS_OpenPrinter ;
String pPrinterName, ;
Integer @phPrinter, ;
String pDefault
DECLARE Integer ClosePrinter in WinSpool.Drv as WS_ClosePrinter ;
Integer hPrinter
DECLARE Integer EnumJobs in WinSpool.Drv as WS_EnumJobs ;
Integer hPrinter, ;
Integer FirstJob, ;
Integer NoJobs, ;
Integer Level, ;
String @pJob, ;
Integer cbBuf, ;
Integer @pcbNeeded, ;
Integer @pcReturned
DECLARE Integer GetLastError in WIN32API as WS_GetLastError
**********************************************************************
* Open the printer
**********************************************************************
lcPrinter=aPrinterList[n,1]
lnHandle=0
IF !EMPTY(lcPrinter)
nRetVal=WS_OpenPrinter(@lcPrinter, @lnHandle, 0)
IF nRetVal != 0
* The printer was opened
ELSE
* The call failed call GetLastError() to retrieve the error number then exit program
lcError=WS_GetLastError()
? lcError
RETURN
ENDIF
ENDIF
**********************************************************************
* Get the number of jobs
**********************************************************************
lnNeeded = 0
lnNumberOfJobs = 0
* Get the size of the buffer in lnNeeded
lnOK = WS_EnumJobs( ;
lnHandle, ;
0, 127, 1, ;
.NULL., ;
2, ;
@lnNeeded, ;
@lnNumberOfJobs)
IF lnOK=0 THEN
IF WS_GetLastError() <> 122 && The buffer too small error
lcErrorTxt = ApiError()
=WS_ClosePrinter( lnHandle)
WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
RETURN -2
ENDIF
ENDIF
* Allocate the buffer
lcBuffer = REPLICATE( CHR(0), lnNeeded)
* Get the number of jobs
lnOK = WS_EnumJobs( ;
lnHandle, ;
0, 127, 1,;
@lcBuffer, ;
@lnNeeded, ;
@lnNeeded, ;
@lnNumberOfJobs )
IF lnOK = 0 THEN
lcErrorTxt = ApiError()
= WS_ClosePrinter( lnHandle )
WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
RETURN -3
ENDIF
**********************************************************************
* Close the printer
**********************************************************************
nClosePrinter=WS_ClosePrinter(lnHandle)
**********************************************************************
* Display the number of jobs in queue
**********************************************************************
? lcPrinter+" has "+ALLTRIM(STR(lnNumberOfJobs))+" jobs in it's queue"
ENDFOR
RETURN
**********************************************************************
* Get List of Printers
**********************************************************************
nNoOfPrinters=APRINTERS(aPrinterList)
FOR n = 1 TO nNoOfPrinters
**********************************************************************
* Declare the API functions
**********************************************************************
DECLARE Integer OpenPrinter in WinSpool.Drv as WS_OpenPrinter ;
String pPrinterName, ;
Integer @phPrinter, ;
String pDefault
DECLARE Integer ClosePrinter in WinSpool.Drv as WS_ClosePrinter ;
Integer hPrinter
DECLARE Integer EnumJobs in WinSpool.Drv as WS_EnumJobs ;
Integer hPrinter, ;
Integer FirstJob, ;
Integer NoJobs, ;
Integer Level, ;
String @pJob, ;
Integer cbBuf, ;
Integer @pcbNeeded, ;
Integer @pcReturned
DECLARE Integer GetLastError in WIN32API as WS_GetLastError
**********************************************************************
* Open the printer
**********************************************************************
lcPrinter=aPrinterList[n,1]
lnHandle=0
IF !EMPTY(lcPrinter)
nRetVal=WS_OpenPrinter(@lcPrinter, @lnHandle, 0)
IF nRetVal != 0
* The printer was opened
ELSE
* The call failed call GetLastError() to retrieve the error number then exit program
lcError=WS_GetLastError()
? lcError
RETURN
ENDIF
ENDIF
**********************************************************************
* Get the number of jobs
**********************************************************************
lnNeeded = 0
lnNumberOfJobs = 0
* Get the size of the buffer in lnNeeded
lnOK = WS_EnumJobs( ;
lnHandle, ;
0, 127, 1, ;
.NULL., ;
2, ;
@lnNeeded, ;
@lnNumberOfJobs)
IF lnOK=0 THEN
IF WS_GetLastError() <> 122 && The buffer too small error
lcErrorTxt = ApiError()
=WS_ClosePrinter( lnHandle)
WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
RETURN -2
ENDIF
ENDIF
* Allocate the buffer
lcBuffer = REPLICATE( CHR(0), lnNeeded)
* Get the number of jobs
lnOK = WS_EnumJobs( ;
lnHandle, ;
0, 127, 1,;
@lcBuffer, ;
@lnNeeded, ;
@lnNeeded, ;
@lnNumberOfJobs )
IF lnOK = 0 THEN
lcErrorTxt = ApiError()
= WS_ClosePrinter( lnHandle )
WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
RETURN -3
ENDIF
**********************************************************************
* Close the printer
**********************************************************************
nClosePrinter=WS_ClosePrinter(lnHandle)
**********************************************************************
* Display the number of jobs in queue
**********************************************************************
? lcPrinter+" has "+ALLTRIM(STR(lnNumberOfJobs))+" jobs in it's queue"
ENDFOR
RETURN