Click to See Complete Forum and Search --> : FindFirstPrinterChangeNotification


pankaj1782
December 4th, 2006, 06:09 AM
hi all,

I am trying to monitor the printer queue by using the Win32 Apis FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification.
But, I am not getting two information....one is the no. of pages printed and the job completion indication.
For the first one I am setting the JOB_NOTIFY_FIELD_PAGES_PRINTED and for the second one JOB_NOTIFY_FIELD_STATUS is being used, in the required member of the PRINTER_NOTIFY_OPTIONS_TYPE structure.

In the case of no. of pages printed, i get correct values, if the document is more than 1 page, but always get 0 when the document is having a single page. why is this so?
And as regard the second thing the JOB_STATUS_PRINTED is never received. My code is as below:


void StartNotifications(void)
{
HANDLE hPrinter = NULL;
PRINTER_NOTIFY_OPTIONS * p_NotifyOptions = NULL;
PRINTER_NOTIFY_OPTIONS_TYPE arr_NotifyOptionsType[2];
PWORD pJobFields, pPrinterFields;
HANDLE hwndNotify = NULL;
DWORD dwChanged = 0;

PRINTER_NOTIFY_INFO * p_OutPut = NULL;

if(OpenPrinter(_T("\\\\NECHCLSTDC\\HP LaserJet 4345 mfp PCL 5e"), &hPrinter, NULL))
{
pJobFields = (PWORD)malloc(5 * sizeof(WORD));
pJobFields[0] = JOB_NOTIFY_FIELD_USER_NAME;
pJobFields[1] = JOB_NOTIFY_FIELD_PAGES_PRINTED;
pJobFields[2] = JOB_NOTIFY_FIELD_TOTAL_BYTES;
pJobFields[3] = JOB_NOTIFY_FIELD_STATUS;
pJobFields[4] = JOB_NOTIFY_FIELD_STATUS_STRING;

arr_NotifyOptionsType[0].Type = JOB_NOTIFY_TYPE ;
arr_NotifyOptionsType[0].pFields = pJobFields;
arr_NotifyOptionsType[0].Count = 5;

pPrinterFields = (PWORD)malloc(2 * sizeof(WORD));
pPrinterFields[0] = PRINTER_NOTIFY_FIELD_PRINTER_NAME;
pPrinterFields[1] = PRINTER_NOTIFY_FIELD_AVERAGE_PPM;

arr_NotifyOptionsType[1].Type = PRINTER_NOTIFY_TYPE ;
arr_NotifyOptionsType[1].pFields = pPrinterFields;
arr_NotifyOptionsType[1].Count = 2;



p_NotifyOptions = new PRINTER_NOTIFY_OPTIONS;

p_NotifyOptions->Count = 2;
p_NotifyOptions->Version = 2;
p_NotifyOptions->pTypes = arr_NotifyOptionsType;
p_NotifyOptions->Flags = PRINTER_NOTIFY_OPTIONS_REFRESH;

if((hwndNotify = FindFirstPrinterChangeNotification(hPrinter, 0, 0, p_NotifyOptions)) != INVALID_HANDLE_VALUE)
{
while(hwndNotify != INVALID_HANDLE_VALUE)
{
if(WaitForSingleObject(hwndNotify, 0) == WAIT_OBJECT_0)
{

FindNextPrinterChangeNotification(hwndNotify, &dwChanged, (LPVOID)p_NotifyOptions, (LPVOID*)&p_OutPut);
for (int i=0;i<p_OutPut->Count;i++)
{
if(p_OutPut->aData[i].Type == JOB_NOTIFY_TYPE)
{
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_USER_NAME)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_PAGES_PRINTED)
{
TCHAR buff[25];
_stprintf(buff,_T("PP = %d Job ID %ld"),p_OutPut->aData[i].NotifyData.adwData[0], p_OutPut->aData[i].Id);
MessageBox(NULL,buff ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS)
{
if(p_OutPut->aData[i].NotifyData.adwData[0] & JOB_STATUS_PRINTED)
MessageBox(NULL,_T("Job Done") ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS_STRING)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
}
}
}
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}



It will be great if some one help me out with this...

Thanks
Pankaj

pankaj1782
December 13th, 2006, 02:10 AM
hi All,

Can some on eplease help me out with the problem....

Thanks
Pankaj

pankaj1782
December 20th, 2006, 01:10 AM
Hi all,

I am trying to monitor a printer, with the help of Find*PrinterChangeNotification API set. The following are my observations:

1. Status notification is not received for any type of Print job,
i.e be it in EMF format or RAW format. In case of Status String notification, the notification was there, but the pBuf was empty.


2. In case of print job with EMF data type, the Total Pages and Printed
pages data was received correctly. Same case for Total Bytes and
Printed Bytes. So, in this wayit can be monitored for a EMF type job that whether it has finished.


3. In case of print job with RAW format, Total pages was received with
correct values, but Printed Pages was always recieved with the value 0.
Total Bytes was OK, but at the end of the print job, the Total Bytes
and Printed Bytes were different, the latter being lesser then former.
So, it doesn't help in determining that whether a print job is finished
or not.

Can some one please help me with the first and third points....
Thanks
Pankaj