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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print status report 1

Status
Not open for further replies.

konLao

Programmer
Mar 10, 2003
61
US
Hi all,

Is there a way to trap printed error or print status from printing window? I have an app. printing report the a remote printer in different room. I need it to be able to notify me if it runs out of paper or it gets paper-jammed.

Thank,

Sam
 
Konlao,

I'm not sure if this work for shared printer, just try this:

------------------
#Define ERROR_INSUFFICIENT_BUFFER 122
#Define PRINTER_STATUS_ERROR 0x02
#Define PRINTER_STATUS_PAPER_JAM 0x08
#Define PRINTER_STATUS_PAPER_OUT 0x10
#Define PRINTER_STATUS_PAPER_PROBLEM 0x40
#Define PRINTER_STATUS_OFFLINE 0x80
#Define PRINTER_STATUS_OUTPUT_BIN_FULL 0x800
#Define PRINTER_STATUS_NOT_AVAILABLE 0x1000
#Define PRINTER_STATUS_NO_TONER 0x40000
#Define PRINTER_STATUS_OUT_OF_MEMORY 0x200000
#Define PRINTER_STATUS_DOOR_OPEN 0x400000
#Define JOB_CONTROL_CANCEL 3
#Define JOB_CONTROL_DELETE 5

Declare Long ClosePrinter in WinSpool.Drv Long hPrinter
Declare Long GetLastError in Kernel32

Declare Long OpenPrinter in WinSpool.Drv ;
String cPrinterName, Long @hPrinter, String pDefault

Declare Long GetJob in WinSpool.Drv ;
Long hPrinter, Long nJobID, Long nLevel, ;
String @cJobInfo, Long nBufSize, Long @nBufNeeded

Local lc_PrinterName, lc_JobInfo, lc_Buffer
Local ln_JobID, ln_Status, ln_Return, ln_hPrinter

lc_PrinterName = GetPrinter()
If !empty(lc_PrinterName)
Store 0 to ln_hPrinter, ln_BufNeeded, ln_Return
If (OpenPrinter(lc_PrinterName, @ln_hPrinter, Null) != 0)
ln_JobID = 1
If (GetJob(ln_hPrinter, 1, 1, 0, 0, @ln_BufNeeded) == 0)
If (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
lc_JobInfo = replicate(chr(0), ln_BufNeeded)
ln_Return = GetJob(ln_hPrinter, 1, 1, @lc_JobInfo, ln_BufNeeded, @ln_BufNeeded)
endif
endif

If (ln_Return > 0)
ln_JobID = DWord2Num(substr(lc_JobInfo, 1, 4))
ln_Status = DWord2Num(substr(lc_JobInfo, (4*7)+1, 4))
? 'Job ID: ', transform(ln_JobID, '@0')
? 'StatusFlag:', transform(ln_Status, '@0')
If (BitAnd(ln_Status, PRINTER_STATUS_ERROR) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_PAPER_JAM) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_PAPER_OUT) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_PAPER_PROBLEM) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_OFFLINE) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_OUTPUT_BIN_FULL) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_NOT_AVAILABLE) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_NO_TONER) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_OUT_OF_MEMORY) != 0) or ;
(BitAnd(ln_Status, PRINTER_STATUS_DOOR_OPEN) != 0)
? ' ***** STATUS ERROR *****'
endif
endif
ClosePrinter(ln_hPrinter)
endif
endif
Clear Dlls
Clear all


Function DWord2Num(tc_Buffer)
Local ln_Result
ln_Result = asc(substr(tc_Buffer, 1,1)) + ;
asc(substr(tc_Buffer, 2,1)) * 256 + ;
asc(substr(tc_Buffer, 3,1)) * 65536 + ;
asc(substr(tc_Buffer, 4,1)) * 16777216

Return ln_Result
EndFunc
------------------

Hope it works

-- AirCon --
 
aircon,
I try your syntax, but there's come error
"Cannot find entry point OpenPrinter in the dll "
 
versillus,

It works fine on my system (ME). What OS are you using?
Maybe you need to change the declaration into this:

Declare Long OpenPrinter in WinSpool.Drv ;
String cPrinterName, Long @hPrinter, @String pDefault


-- AirCon --
 
Whhoops!

Sorry, It should be this:

Declare Long OpenPrinter in WinSpool.Drv ;
String cPrinterName, Long @hPrinter, String @pDefault


-- AirCon --
 
AirCon,

Thank you for responding. I know it's been a while back. I just now have a chance to play with it. I can't seem to get it to work for me. I stepped through the code and found that

?GetLastError()

I would get 87[/color red] instead of 122[/color red] (ERROR_INSUFFICIENT_BUFFER).
Eventhough I commented out the IF condition, ln_Return would get 0[/color red] value. Any idea?

Thank you,

Konlao
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top