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

Posted on 2000-04-06
Medium Priority
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?

Question by:zhiyong
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 14

Accepted Solution

AlexVirochovsky earned 600 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_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,
       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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

752 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