Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindNextPrinterChangeNotification 1

Status
Not open for further replies.

ids4ids

Technical User
Jun 17, 2004
26
0
0
RO
Hi,

I use the code from below to monitor a printer queue and
I want to know when and what it's changing.

From my tests dwChange has decimal values which I don't know what is meaning and AdrBuffer is always zero.

Can anybody tell me what are the values of variable dwChange and their meaning ?
When AdrBuffer is non zero ?

.
.
.
nhPrinterChangeNotification=FindFirstPrinterChangeNotification(nhPrinter,PRINTER_CHANGE_ALL,0,0)
IF nhPrinterChangeNotification=INVALID_HANDLE_VALUE
ClosePrinter(nhPrinter)
RETURN -4
ENDIF
*
DO WHILE .T.
nReturnValue=WaitForSingleObject(nhPrinterChangeNotification,INFINITE)
IF nReturnValue=WAIT_OBJECT_0
FindNextPrinterChangeNotification(nhPrinterChangeNotification,@dwChange,0,@AdrBuffer)

? dwChange
? AdrBuffer

FreePrinterNotifyInfo(AdrBuffer)

IF dwChange=1538
EXIT
ENDIF

ENDIF
ENDDO
.
.
.
Thank you in advance.
 
The online MSDN is the first source of informations about API calls.


dwChange values correspond to PRINTER_CHANGE_... constants mentioned in the MSDN.

AdrBuffer rather is the *ppPrinterNotifyInfo parameter. I don't see from your code how you initialize this. From the help I assume the output of that parameter is set within the structure, only if you set a certain Flag in it. maybe the output of dwChange is enough for you and you do not need to care more about this.

To find out the constants values, the help says these are defined in winspool.h. Such header files can be found in several SDKs, but I often simply google for them.

Code:
#define PRINTER_CHANGE_ADD_PRINTER              0x00000001
#define PRINTER_CHANGE_SET_PRINTER              0x00000002
#define PRINTER_CHANGE_DELETE_PRINTER           0x00000004
#define PRINTER_CHANGE_FAILED_CONNECTION_PRINTER    0x00000008
#define PRINTER_CHANGE_PRINTER                  0x000000FF
#define PRINTER_CHANGE_ADD_JOB                  0x00000100
#define PRINTER_CHANGE_SET_JOB                  0x00000200
#define PRINTER_CHANGE_DELETE_JOB               0x00000400
#define PRINTER_CHANGE_WRITE_JOB                0x00000800
#define PRINTER_CHANGE_JOB                      0x0000FF00
#define PRINTER_CHANGE_ADD_FORM                 0x00010000
#define PRINTER_CHANGE_SET_FORM                 0x00020000
#define PRINTER_CHANGE_DELETE_FORM              0x00040000
#define PRINTER_CHANGE_FORM                     0x00070000
#define PRINTER_CHANGE_ADD_PORT                 0x00100000
#define PRINTER_CHANGE_CONFIGURE_PORT           0x00200000
#define PRINTER_CHANGE_DELETE_PORT              0x00400000
#define PRINTER_CHANGE_PORT                     0x00700000
#define PRINTER_CHANGE_ADD_PRINT_PROCESSOR      0x01000000
#define PRINTER_CHANGE_DELETE_PRINT_PROCESSOR   0x04000000
#define PRINTER_CHANGE_PRINT_PROCESSOR          0x07000000
#define PRINTER_CHANGE_ADD_PRINTER_DRIVER       0x10000000
#define PRINTER_CHANGE_SET_PRINTER_DRIVER       0x20000000
#define PRINTER_CHANGE_DELETE_PRINTER_DRIVER    0x40000000
#define PRINTER_CHANGE_PRINTER_DRIVER           0x70000000
#define PRINTER_CHANGE_TIMEOUT                  0x80000000
#define PRINTER_CHANGE_ALL                      0x7777FFFF

In this case, the return value of dwChange is a sum of several of these constants. The code waits for 1538, which is 0x0602, so it waits for PRINTER_CHANGE_SET_PRINTER and PRINTER_CHANGE_SET_JOB and PRINTER_CHANGE_DELETE_JOB.

Bye, Olaf.
 
I know about these contants but can you explain why 0x602 means PRINTER_CHANGE_SET_PRINTER and PRINTER_CHANGE_SET_JOB and PRINTER_CHANGE_DELETE_JOB ? ... I must looking for bits change or something like this ?

How can I obtain the changed job ID identifier ?
 
I mean job ID identifier of changed job...
 
Yes, these values are additive. With the exception of PRINTER_CHANGE_PRINTER and PRINTER_CHANGE_ALL the constants stand for one bit each. 0x602 is 0x400+0x200+0x002.

For finding out, which bit is set simply bitand the returnvalue with each constant. If the result of that is 0, the bit is not set, if it is the value of the constant, that Change happened.

Bye, Olaf.
 
Thank you Olaf.

Can you help me to obtain ID identifier of changed print job ?
 
Hi,

well, then you are waiting for any of PRINTER_CHANGE_ADD_JOB, PRINTER_CHANGE_SET_JOB , PRINTER_CHANGE_DELETE_JOB, PRINTER_CHANGE_WRITE_JOB or PRINTER_CHANGE_JOB

eg:
Code:
if bitand(dwChange,PRINTER_CHANGE_JOB) = PRINTER_CHANGE_JOB
   *job changed
endif

if bitand(dwChange,PRINTER_CHANGE_DELETE_JOB) = PRINTER_CHANGE_DELETE_JOB
   *a job was deleted
endif

Bye, Olaf.
 
I mean job ID indentifier from printer queue.
For example,
if bitand(dwChange,PRINTER_CHANGE_JOB) = PRINTER_CHANGE_JOB
*print job id identifier from queue (which print job)
endif
if bitand(dwChange,PRINTER_CHANGE_DELETE_JOB) = PRINTER_CHANGE_DELETE_JOB
*print job id identifier from queue
endif
 
Here the printer_notify_info_data is described. I don't knwo what you need to pick out of that to get the job id. Maybe start a new question about that. Maybe that is not the scope of the FindNextPrinterChangeNotification function, although jsut browsing that page you get a lot of infos from that structure.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top