Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Queue using Win32API

Status
Not open for further replies.

ChrisSutcliffe

Programmer
Jan 13, 2005
2
GB
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
 
thanks for your reply, I have already seen that site and I cant really warrant paying the subscription for only one program.

If anyone is still willing to help with this I would appreciate it.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top