Solved

How to varify the printing status in C++ in LAN printer.

Posted on 2000-04-06
1
260 Views
Last Modified: 2008-02-20
IF I sent some document to print in the shared LAN printer printing pools, How to get the result in C++ that a document has been printed and cleared in the printing pools? (OS: Windows NT)

f.e. I sent 1.doc, 2.doc, 3.doc in order, and after 1.doc finished, How to get an infomation to deal with in the C++ application?

0
Comment
Question by:zhiyong
1 Comment
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 2692287
To get printer status:http://support.microsoft.com/support/kb/articles/q160/1/29.asp
Example of using:
   BOOL IsPrinterError(HANDLE hPrinter)   {       JOB_INFO_2  *pJobs;
       int         cJobs,                   i;
       DWORD       dwPrinterStatus;       /*
        *  Get the state information for the Printer Queue and
        *  the jobs in the Printer Queue.        */
       if (!GetJobs(hPrinter, &pJobs, &cJobs, &dwPrinterStatus))
           return FALSE;       /*
        *  If the Printer reports an error, believe it.        */
       if (dwPrinterStatus &           (PRINTER_STATUS_ERROR |
           PRINTER_STATUS_PAPER_JAM |           PRINTER_STATUS_PAPER_OUT |
           PRINTER_STATUS_PAPER_PROBLEM |
           PRINTER_STATUS_OUTPUT_BIN_FULL |
           PRINTER_STATUS_NOT_AVAILABLE |           PRINTER_STATUS_NO_TONER |
           PRINTER_STATUS_OUT_OF_MEMORY |           PRINTER_STATUS_OFFLINE |
         PRINTER_STATUS_DOOR_OPEN))       {           return TRUE;       }
   BOOL GetJobs(HANDLE hPrinter,        /* Handle to the printer. */
                JOB_INFO_2 **ppJobInfo, /* Pointer to be filled.  */
                int *pcJobs,            /* Count of jobs filled.  */
                DWORD *pStatus)         /* Print Queue status.    */    {
       DWORD               cByteNeeded,                           nReturned,
                           cByteUsed;
       JOB_INFO_2          *pJobStorage = NULL;
       PRINTER_INFO_2       *pPrinterInfo = NULL;
   /* Get the buffer size needed. */
       if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))       {
           if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
               return FALSE;       }
       pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
       if (!(pPrinterInfo))           /* Failure to allocate memory. */
           return FALSE;       /* Get the printer information. */
       if (!GetPrinter(hPrinter,               2,
               (LPSTR)pPrinterInfo,               cByteNeeded,
               &cByteUsed))       {
           /* Failure to access the printer. */            free(pPrinterInfo);
           pPrinterInfo = NULL;           return FALSE;       }
       /* Get job storage space. */
       if (!EnumJobs(hPrinter,
               0,pPrinterInfo->cJobs,               2,
               NULL,               0,               (LPDWORD)&cByteNeeded,
               (LPDWORD)&nReturned))       {
           if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)           {
               free(pPrinterInfo);               pPrinterInfo = NULL;
               return FALSE;           }       }
       pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);       if (!pJobStorage)
       {           /* Failure to allocate Job storage space. */
           free(pPrinterInfo);           pPrinterInfo = NULL;
         return FALSE;       }       ZeroMemory(pJobStorage, cByteNeeded);
       /* Get the list of jobs. */        if (!EnumJobs(hPrinter,
             0,               pPrinterInfo->cJobs,               2,
             (LPBYTE)pJobStorage,               cByteNeeded,
             (LPDWORD)&cByteUsed,               (LPDWORD)&nReturned))       {
         free(pPrinterInfo);           free(pJobStorage);
         pJobStorage = NULL;           pPrinterInfo = NULL;
         return FALSE;       }       /*        *  Return the information.
      */        *pcJobs = nReturned;       *pStatus = pPrinterInfo->Status;
       *ppJobInfo = pJobStorage;       free(pPrinterInfo);       return TRUE;
   }

I hope, it helps. Alex
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question