PrinterLib 1.10

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

This might help:
SetJob()

Something like this:

Code: Select all

SetJob_(hPrinter, iJobId, 0, #Null, #JOB_CONTROL_DELETE)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PrinterLib 1.10

Post by TI-994A »

yrreti wrote:...after it is sent to the printer, and I realize that I made a mistake in the info I was printing, is there a way to cancel the print job...?
...because it's running from the printers memory at that point.
Hi yrreti. Once the job is no longer in the OS's print spooler queue, the only available action would be to cancel it physically from the printer's control panel, or on some models, the software control panel. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Once the job is no longer in the OS's print spooler queue
That must be a set-up thing (which is a pity as you probably would not be able to control the settings on a customer's PC).

On my PC, the print queue displays the current print job until the printing is completed and so you can halt printing during the process. If you are printing 50 sheets and then stop the process, it will continue printing the current sheet but then no more. I imagine this is what you would like to be able to do from your app.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PrinterLib 1.10

Post by ABBKlaus »

Try this one :

http://msdn.microsoft.com/en-us/library ... s.85).aspx

Code: Select all

PH=Print_GetPrinterHandle()
If AbortPrinter_(PH)
  Debug "AbortPrinter ok"
EndIf
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PrinterLib 1.10

Post by TI-994A »

IdeasVacuum wrote:That must be a set-up thing (which is a pity as you probably would not be able to control the settings on a customer's PC).

On my PC, the print queue displays the current print job until the printing is completed and so you can halt printing during the process. If you are printing 50 sheets and then stop the process, it will continue printing the current sheet but then no more. I imagine this is what you would like to be able to do from your app.
Hi IdeasVacuum. The OS's print spooler will display the print jobs in queue until it has been completely sent to the printer; not until the printing has completed. Many printers have built-in memory which receive and store the print jobs, freeing up the OS's spooler. Print jobs sent to my Brother MFC-7840N (32MB), and Fuji-Xerox CM215FW (128MB), get cleared from the OS's print queue almost instantly, sometimes even before a single page gets printed. Your system displays the print progress synchronously with the physical printout perhaps because your printer is not equipped with such memory.

As far as I know, there's no OS API function to programmatically abort print jobs once they've been sent to the printer's memory, and cleared from the system spool.

Hello ABBKlaus. I believe that even the AbortPrinter() function is simply for deleting a particular printer's spool in system memory, and not on the printer itself. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Hi TI-994A

In the case of Printers with larger memory, I think they mostly still use on-board GDI. So, that memory is being used to store the pages of data for rapid printing, but there will be a regular call-back to the OS to allow it to send an abort instruction. I can't imagine any printer manufacturer not providing this essential facility.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PrinterLib 1.10

Post by TI-994A »

IdeasVacuum wrote:...there will be a regular call-back to the OS to allow it to send an abort instruction. I can't imagine any printer manufacturer not providing this essential facility.
You'd think that, but you'd be surprised. Because they don't. :D
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

...Not convinced. It absolutely has to be possible, since larger capacity printers could be on a completely separate floor in the building, so the on-device facility would not be appropriate. I have certainly always been able to cancel printing via Windows on the office printers I have used (which must be hundreds by now :shock: ) , including Xerox printers which are very popular in the UK.

MSDN does suggest the AbortPrinter() function is a message sent to the printer itself:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PrinterLib 1.10

Post by Thunder93 »

AbortPrinter function

This is a blocking or synchronous function and might not return immediately. How quickly this function returns depends on run-time factors such as network status, print server configuration, and printer driver implementation—factors that are difficult to predict when writing an application. Calling this function from a thread that manages interaction with the user interface could make the application appear to be unresponsive.

If the printer is not configured for spooling, the AbortPrinter function has no effect.

"network status" clear indication. AbortPrinter function then should work.. if Printer is configured for spooling. What to use when Spooling isn't configured? :?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

What to use when Spooling isn't configured?
Well, that's where I thought SetJob() would be used

Code: Select all

SetJob_(hPrinter, iJobId, 0, #Null, #JOB_CONTROL_DELETE)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PrinterLib 1.10

Post by Thunder93 »

Nice!
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

WoW! all the comments. Got busy and couldn't get back to this post until now.

IdeasVacuum's idea using SetJob() worked absolutely great.

Code: Select all

SetJob_(hPrinter, iJobId, 0, #Null, #JOB_CONTROL_DELETE
and ABBKlaus code to get the print handle.

Code: Select all

PH=Print_GetPrinterHandle()
If AbortPrinter_(PH)
  Debug "AbortPrinter ok"
EndIf
and TI-994A for his added info and help.

I want to sincerely thank all of you for your input and help in solving this issue that I had. :D :D :D
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PrinterLib 1.10

Post by TI-994A »

Hi yrreti. Apologies for the digression, but so glad to hear that you found a solution. :D
IdeasVacuum wrote:... larger capacity printers could be on a completely separate floor in the building, so the on-device facility would not be appropriate.
You're right about that, but such printers usually come with their own software monitors that are equipped to purge jobs from their memories. But since such hardware features are non-standard, OSes usually aren't able to initiate them.

AbortPrinter() is also a spooler function, and all it does is delete the system spool file associated with a specified printer, effectively deleting every job in queue for that printer. Compare this with the SetJob() function called with the JOB_CONTROL_DELETE command, which deletes only the specified job ID from the queue. In both cases, however, deletion takes place only in the system memory, and not the printer's. Any data stream that has left the spooler is irretrievable, and thus cannot be deleted by the system.

A picture is always worth a thousand words, and the best way to confirm this is QED (if you have a printer with cache memory). Simply open up the spooler window for that printer, initiate a lengthy print job, and then call AbortPrinter() or SetJob(...JOB_CONTROL_DELETE) after the job has cleared from the spooler window, but while the printer is still printing.

They'll both return with zero, and the printing will continue to completion. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PrinterLib 1.10

Post by Thunder93 »

SetPrinter another Spooler API function, that works on a global scale.
If you have a small print job, and the printer already in the process of printing. I don't remember if cancelling via Windows Print screen was ever effective. If I can remember correctly, it always continued to print the remainder of the job. Clearing all the jobs, the one that the printer was working on always finished and then stops.

Maybe if the job was a lengthy one, perhaps It would eventually halt before print completion. But Office printers with large memory, .. I don't think it would be possible via Windows own controls to cancel a print job, but should be-able to clear everything else queued.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Thanks for all the good information, and unfortunately I find that your right.
I didn't have much time to check it out, and was a little bit quick and excited that I didn't check it out fully. :oops:
The code does work just before and when the printer just starts to become active (motors running).
So I thought it worked. But once the printer starts printing, it doesn't. And that's what I was looking for in the
first place. Like the saying goes. Haste makes waste, and also makes one fill stupid. :oops: :oops: :oops:
Sorry for the overly quick and wrong response. But I don't want to mislead someone else that the code does work.
Post Reply