0

I'm trying to capture the printer job details, and my program is working fine, except on one machine. The value returned by Data.NotifyData.adwData[0] is 8208(in Decimal) and it doesn't match with any of the predefined values, I searched about this and couldn't find any info, and the GetLastError returned a 0.

 PRINTER_NOTIFY_INFO_DATA &Data = pNotification->aData[x];
    if( Data.Type == JOB_NOTIFY_TYPE )
        {
            switch( Data.Field )
            {
                case JOB_NOTIFY_FIELD_STATUS:

                    printf("Case:JOB_NOTIFY_FIELD_STATUS,adwData[0]:%x\n",Data.NotifyData.adwData[0]);
                    if(Data.NotifyData.adwData[0] == JOB_STATUS_SPOOLING) 
                    {
                        //SetEvent
                    }
                    if(Data.NotifyData.adwData[0] == JOB_STATUS_PRINTING) 
                    {
                        //SetEvent
                    }

                break;
            }
        }
San852
  • 19
  • 8

1 Answers1

2

The documentation for job status values says:

This member can be one or more of the following values.

This is Microsoft code to introduce a value that is made by combining bit flags using bitwise OR.

Your value is 0x2010 which is the following combination of values defined in Winspool.h:

  • 0x2000, JOB_STATUS_RETAINED
  • 0x0010, JOB_STATUS_PRINTING

So your value is JOB_STATUS_RETAINED | JOB_STATUS_PRINTING.

In any case, you should not test the entire value directly. You need to test bitwise:

DWORD status = Data.NotifyData.adwData[0];
if (status & JOB_STATUS_PAUSED) 
    // ... 
if (status & JOB_STATUS_ERROR) 
    // ... 
if (status & JOB_STATUS_DELETING) 
    // ... 
if (status & JOB_STATUS_SPOOLING) 
    // ... 
if (status & JOB_STATUS_PRINTING) 
    // ... 
// and so on for each status bit that is of interest
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Isn't it the [constants starting with `JOB_`](https://msdn.microsoft.com/en-us/library/windows/desktop/dd145020\(v=vs.85\).aspx) that should be referred to here? – Ken Y-N Nov 24 '16 at 06:04
  • But there is sufficient paper and even printed out the document ! – San852 Nov 24 '16 at 06:14
  • [JOB_STATUS_RETAINED](http://www.rdos.net/svn/tags/V9.2.5/watcom/bld/w32api/include/winspool.mh) perhaps? And a [Stack Overflow link](https://stackoverflow.com/questions/15748386/how-to-catch-printer-event-in-python). – Ken Y-N Nov 24 '16 at 06:17
  • Okay thanks, I'll look for the up to date winspool.h and get back, also I'm not sure about the printer driver installed on that machine, is it possible that this might be because of old/other driver issues? – San852 Nov 24 '16 at 06:17
  • @KenY-N JOB_STATUS_RETAINED is 0x2000, but the value returned was 0x2010 – San852 Nov 24 '16 at 06:19
  • `JOB_STATUS_PRINTING | JOB_STATUS_RETAINED`. – Ken Y-N Nov 24 '16 at 06:19