| 
			Author: Tomas Rutkauskas
Is there any way in Delphi to check for the printer queue or if a printer has 
received and printed a document correctly?
Answer:
No there is not any bullet-proof way of determining that a document has been 
printed correctly. Nevertheless here is a routine to collect all the running jobs 
of a printer. Keep in mind that the only way to retrieve this information is by 
pooling it from the spooler in standard intervals.
1   { ... }
2   type
3     PJobInfoArray = ^TJobInfoArray;
4     TJobInfoArray = array[0..0] of winspool.JOB_INFO_2;
5   
6   procedure GetJobs(APrinter: string);
7   var
8     Size, Needed, Returned, CNT: Cardinal;
9     Res: LongBool;
10    Prn: Cardinal;
11    PrnName: Pchar;
12    vJobs: PJobInfoArray;
13  begin
14    ReAllocMem(PrnName, Length(aPrinter) + 2);
15    CopyMemory(PrnName, @aPrinter[1], Length(aPrinter));
16    Res := OpenPrinter(PrnName, Prn, nil);
17    ReAllocMem(PrnName, 0);
18    if LongInt(Res) = 0 then
19      RaiseLastOSError;
20    Size := 0;
21    Res := WinSpool.EnumJobs(Prn, 0, 999, 2, VJobs, 0, Needed, Returned);
22    Size := Needed;
23    reAllocMem(VJobs, Size);
24    Res := EnumJobs(Prn, 0, 999, 2, vJobs, Size, Needed, Returned);
25    if LongInt(Res) > 0 then
26    begin
27      reAllocMem(vJobs, 0);
28      ClosePrinter(Prn);
29      RaiseLastOSError;
30    end;
31    ReAllocMem(VJobs, 0);
32    ClosePRinter(Prn);
33  end;
			 |