Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Monitor Printer Queue / SpyPrinter from Peter Below


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Mar 19, 2018 12:05 PM Last Post By: Remy Lebeau (Te...
Stefan Westner

Posts: 36
Registered: 10/14/99
Monitor Printer Queue / SpyPrinter from Peter Below  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 2:58 AM
Hallo,

I want monitor the printer queue / printer spooler.

13 years ago Peter Below posted:
http://cc.embarcadero.com/Item/20307

I gave it a look under Delphi 2007 and in general it works fine but with some problems:

1. The document name is always "Lokale Druckerdatendatei" (english: local printerdatafile) and not for example "Microsoft Word - Document1" as the job is listed in the spooler

2. If I compile the code with range checks on then I get errors at runtime:
For i:=0 To pni^.Count-1 Do
  Case pni^.aData[i].Field Of


TPrinterNotifyInfoData is created by windows in the message Count-1 but in the WinSpool it is only declared as array[0..0].
  _PRINTER_NOTIFY_INFO = record
    Version: DWORD;
    Flags: DWORD;
    Count: DWORD;
    aData: array[0..0] of TPrinterNotifyInfoData;
  end;

Switching of range check and accessing it count-1 would be ok but that's more a C-way then a delphi way. How could this solved more delphi-like?

3. Pagenumber, Print data Size, ... are not read vom the spoolerdata

Does anybody modified / improved the component?

Greetings

Stefan
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Monitor Printer Queue / SpyPrinter from Peter Below  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 11:04 AM   in response to: Stefan Westner in response to: Stefan Westner
Stefan Westner wrote:

Hallo,

I want monitor the printer queue / printer spooler.

13 years ago Peter Below posted:
http://cc.embarcadero.com/Item/20307

Has it really been 13 years already? Wow, I swear the years are not as
long as they used to be <g>.


I gave it a look under Delphi 2007 and in general it works fine but
with some problems:

1. The document name is always "Lokale Druckerdatendatei" (english:
local printerdatafile) and not for example "Microsoft Word -
Document1" as the job is listed in the spooler

Do you see this for a notification with the notification code
JOB_NOTIFY_FIELD_DOCUMENT? That would indicate that the problem is in
the print spooler or driver. I don't remember which notification the
sample application I posted displays here, sorry.


2. If I compile the code with range checks on then I get errors at
runtime:
For i:=0 To pni^.Count-1 Do
  Case pni^.aData[i].Field Of


TPrinterNotifyInfoData is created by windows in the message Count-1
but in the WinSpool it is only declared as array[0..0].
  _PRINTER_NOTIFY_INFO = record
    Version: DWORD;
    Flags: DWORD;
    Count: DWORD;
    aData: array[0..0] of TPrinterNotifyInfoData;
  end;

Switching of range check and accessing it count-1 would be ok but
that's more a C-way then a delphi way. How could this solved more
delphi-like?

Unfortunately not. The printer and spooler API is very C-oriented and
full of C structures that are actually of variable size and thus cannot
be exactly declared as a Delphi record. A declaration like the above
one is the closest you can get, and it only works if range checking is
off.

3. Pagenumber, Print data Size, ... are not read vom the spoolerdata

See
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162854%28v=vs
.85%29.aspx for the docs on what to expect in the notification.

The code I posted was basically a Delphi translation of a C code
example posted by somebody else, and I had no real way to test the
result due to a lack of a suitable test system.

--
Peter Below
TeamB

Chris Nillissen

Posts: 60
Registered: 11/5/06
Re: Monitor Printer Queue / SpyPrinter from Peter Below  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 19, 2018 4:59 AM   in response to: Peter Below in response to: Peter Below
Peter, Do you know if there is a way to get the Process ID for each given print job?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Monitor Printer Queue / SpyPrinter from Peter Below  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 19, 2018 12:05 PM   in response to: Chris Nillissen in response to: Chris Nillissen
Chris Nillissen wrote:

Do you know if there is a way to get the Process ID for each
given print job?

Printer jobs don't keep track of that information. And if you think
about it, that is not very useful information anyway. Once a print job
has been submitted to the spooler, it is queued for printing, and the
submitting process could exit before the job is actually printed.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02