Re: how to check the status of a printer by Jiping
Jiping
Wed Jul 23 21:14:05 CDT 2008
On Wed, 23 Jul 2008 11:42:59 +0200, "Alf P. Steinbach" <alfps@start.no> wrote:
>* Jiping Tao:
>> hi,
>> I am do some printing programming in vs6.0. I have to check the
>> status of a printer. I try to use the API of "OpenPrinter" and
>> "GetPrinter", and retrieve a struct of PPRINTER_INFO_2. but the member
>> of "status" in PPRINTER_INFO_2 is always equal to zero no matter
>> whether the printer is connected to the PC. the code is as follows
>>
>> //==========
>> HANDLE phPrinter;
>> if(OpenPrinter(pPrinterName,&phPrinter,NULL))
>> {
>> DWORD buffsize;
>> GetPrinter(phPrinter,2,NULL,0,&buffsize);
>> PPRINTER_INFO_2 pInfo = (PPRINTER_INFO_2)new unsigned char[buffsize];
>> GetPrinter(phPrinter,2,(LPBYTE)pInfo,buffsize,&buffsize);
>> pInfo->Status;// it is always equal to 0;
>> }
>> //==========
>> who can help me? Thank you.
>
>Trying out your code it reports e.g. printer driver name correctly and status
>zero as you experience, so it's reproduced (I used GetDefaultPrinter for printer
>name).
>
>KB article Q202480 (I guess that with the new numbering it's 202480) says:
>
><q>
>NOTE: The system only checks the status when the system has a job to spool.
>Otherwise, the queue is considered "ready" because the queue can accept jobs,
>even if the hardware is in an error state. For example, if the last job that was
>printed used the last piece of paper, the operating system does not know this
>until the system tries to print again.
>
>Additionally, although there are many statuses that may be reported, many are
>not supported in practice. The printer hardware and the port monitor determine
>which statuses to report. For example, if the printer is out of paper and
>offline, the status may be reported as "Printing" because that is what the job
>is trying to do. Therefore, a queue that displays "Ready" does not guarantee
>that your print job will complete successfully.
></q>
>
>Plus, some hazy memory says the once upon a time it was essential to use the
>print dialog in order to get valid information, but I'm not sure whether that
>was something I experienced or was told about (in which case it might have been
>incorrect), and t'was long ago, so may not apply now anyway.
>
>
>Cheers, & hth.,
>
>- Alf
>
>
>PS: Tip: you can use std::vector<char> to allocate a buffer that's automatically
>deallocated for you, and is exception-safe. Use &v[0] to get a buffer pointer.
many thanks for your kindly reply. However, do you mean there is no method to check the status of a printer, unless we send a request to print?
how can we know whether our printing job can be executed on a specified printer, immediately or after a while.