Solved

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

Posted on 2000-04-06
1
252 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now