3.2.4.2.3 Enumerating Jobs on a Printer
To enumerate the jobs that are currently queued to a printer, the print client performs the following steps:
Invoke RpcOpenPrinter, supplying the name of the target printer in the pPrinterName parameter and an AccessRequired value that includes PRINTER_ACCESS_USE.
Using the printer handle that was obtained from RpcOpenPrinter:
Set a local job position context to the desired starting index, typically zero.
Set a local number of jobs to return in a single operation.<417>
Until an RpcEnumJobs call returns with a success status and a pcReturned pointing to a value of zero, or until the expected set of jobs has been returned:
Invoke RpcEnumJobs, supplying the job position context in FirstJob, the number of jobs to return in a call in NoJobs, the desired information level in Level, a pointer to the job information buffer in pJob, the size of the job information buffer in cbBuf, a pointer to a variable to store the required buffer size in pcbNeeded, and a pointer to a variable to store the number of job information structures returned in pcReturned.
While RpcEnumJobs returns with ERROR_INSUFFICIENT_BUFFER [MS-ERREF]:
Allocate a new job information buffer with the size returned in pcbNeeded.
Invoke RpcEnumJobs, supplying the job position context in FirstJob, the number of jobs to return in a call in NoJobs, the desired information level in Level, a pointer to the job information buffer in pJob, the size of the job information buffer in cbBuf, a pointer to a variable to store the required buffer size in pcbNeeded, and a pointer to a variable to store the number of job information structures in pcReturned.
Note: Because the number of jobs can change at any time, the client SHOULD be prepared to receive ERROR_INSUFFICIENT_BUFFER even after allocating the correct buffer size the first time.
Increase the local job position context by the value supplied in pcReturned.
The client SHOULD invoke RpcClosePrinter with the printer handle obtained from RpcOpenPrinter or repeat step 2 if there are further job enumeration requests to make.