Home > Software engineering >  Bitmap WinDDK a printer driver
Bitmap WinDDK a printer driver

Time:09-24

Everybody is good, ask a technical question
I use WinDDK inside bitmap source compiled a printer driver, how to get to the current name of the print job?

CodePudding user response:

After the OpenPrinter EnumJobs or GetJob
Refer to the MSDN examples
 
BOOL ListJobsForPrinter (LPTSTR szPrinterName)
{
HANDLE hPrinter;
DWORD dwNeeded dwReturned, I;
JOB_INFO_1 * pJobInfo;

//You need a printer handle and open the printer
if( ! OpenPrinter (szPrinterName, & amp; HPrinter, NULL))
Return FALSE;

//First you call EnumJobs () to find out how much memory you need
if( ! EnumJobs (hPrinter, 0, 0 XFFFFFFFF, 1, NULL, 0, & amp; DwNeeded,
& DwReturned))
{
//It should have failed, but if It failed for any reason other
//than "not enough memory", you should bail out
If (GetLastError ()!=ERROR_INSUFFICIENT_BUFFER)
{
ClosePrinter (hPrinter);
Return FALSE;
}
}
//the Allocate enough memory for the JOB_INFO_1 structures plus
//the extra data - dwNeeded from the previous call tells you
//the total size men
If ((pJobInfo=(JOB_INFO_1 *) malloc (dwNeeded))==NULL)
{
ClosePrinter (hPrinter);
Return FALSE;
}
//Call EnumJobs (again) and let it fill out our structures
if( ! EnumJobs (hPrinter, 0, 0 XFFFFFFFF, 1, (LPBYTE) pJobInfo,
DwNeeded, & amp; DwNeeded, & amp; DwReturned))
{
ClosePrinter (hPrinter);
Free (pJobInfo);
Return FALSE;
}
//You 'r e done with the printer handle, close it
ClosePrinter (hPrinter);

//dwReturned tells how many jobs there are
//Here, you 'l l simple display the number of jobs found
Printf (" % d jobs \ n ", dwReturned);
//It 's easy to loop through the jobs and access each one
for(i=0; i{
//pJobInfo [I] is a JOB_INFO_1 struct for that job
//so here you could do whatever you want for each job
Printf (" % [d]] [% s \ n ", pJobInfo [I] JobId, pJobInfo [I] pDocument);
}

//Clean up
Free (pJobInfo);
Return TRUE;
}

  • Related