San852
San852

Reputation: 19

Undefined data returned from the the structure PRINTER_NOTIFY_INFO_DATA

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;
            }
        }

Upvotes: 0

Views: 164

Answers (1)

David Heffernan
David Heffernan

Reputation: 613372

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

Upvotes: 2

Related Questions