Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is twain_32.dll cmpatible with windows 10 ? 10 226
How to gracefully close the c++ 11 thread? 3 119
max float value 3 59
FMX TEdit KeyUp handler detecting  "enter" key 4 36
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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 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.

685 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