FindNextPrinterChangeNotification - Invalid Handle
-
I've written a VC++ 6.0 app (based on Microsoft's Printmon example) that uses printer notification api's. These work fine for local printers but whenever I try a network printer (\\server\printer name) my application fails with an Invalid Handle from the FindNextPrinterChangeNotification api call. The Printmon example also does this. My client is XP with SP2 and the servers holding the queues are Windows 2000 and Windows 2003, anyone any ideas ?
-
I've written a VC++ 6.0 app (based on Microsoft's Printmon example) that uses printer notification api's. These work fine for local printers but whenever I try a network printer (\\server\printer name) my application fails with an Invalid Handle from the FindNextPrinterChangeNotification api call. The Printmon example also does this. My client is XP with SP2 and the servers holding the queues are Windows 2000 and Windows 2003, anyone any ideas ?
If u r using \\server\printer name as a string forget not to include '\' before each '\' , means "\\\\Server\\printer name" should be used. Appu.. "If you judge people, you have no time to love them."
-
If u r using \\server\printer name as a string forget not to include '\' before each '\' , means "\\\\Server\\printer name" should be used. Appu.. "If you judge people, you have no time to love them."
Check this sample . http://msdn2.microsoft.com/en-us/library/54z247f9.aspx[^] Appu.. "If you judge people, you have no time to love them."
-
Check this sample . http://msdn2.microsoft.com/en-us/library/54z247f9.aspx[^] Appu.. "If you judge people, you have no time to love them."
-
Printername for network printer is in the correct format, my call to OpenPrinter is successful. Its the call to FindNextPrinterChangeNotification that is actually failing with an invalid handle.
Use the Handle returned by OpenPrinter , as the input Handle for FindNextPrinterChangeNotification Appu.. "If you judge people, you have no time to love them."
-
Use the Handle returned by OpenPrinter , as the input Handle for FindNextPrinterChangeNotification Appu.. "If you judge people, you have no time to love them."
You seem to have missed the point ... I know openprinter returns a handle which is then used by FindFirstPrinterChangeNotification which itself returns a handle which is then used by the FindNextPrinterChangeNotification api. I've written out several items including the handle values, which are correct and don't change between the FindFirst and FindNext calls, but the FindNext call always errors with an invalid handle - but why with network printers ?
-
I've written a VC++ 6.0 app (based on Microsoft's Printmon example) that uses printer notification api's. These work fine for local printers but whenever I try a network printer (\\server\printer name) my application fails with an Invalid Handle from the FindNextPrinterChangeNotification api call. The Printmon example also does this. My client is XP with SP2 and the servers holding the queues are Windows 2000 and Windows 2003, anyone any ideas ?
P Gibson wrote:
...my application fails with an Invalid Handle from the FindNextPrinterChangeNotification api call.
What does
GetLastError()
return?
"The largest fire starts but with the smallest spark." - David Crow
-
P Gibson wrote:
...my application fails with an Invalid Handle from the FindNextPrinterChangeNotification api call.
What does
GetLastError()
return?
"The largest fire starts but with the smallest spark." - David Crow
Using the tried and trusted ErrorBox method as follows void ErrorBox (DWORD dwError, LPCSTR lpString) { #define MAX_MSG_BUF_SIZE 512 char *msgBuf; DWORD cMsgLen; cMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | 40, NULL, dwError, MAKELANGID(0, SUBLANG_ENGLISH_US), (LPTSTR) &msgBuf, MAX_MSG_BUF_SIZE, NULL); MessageBox( NULL, msgBuf, lpString, MB_OK ); LocalFree( msgBuf ); #undef MAX_MSG_BUF_SIZE it displays ... each and every time for a network printer ! The handle is invalid.
-
Using the tried and trusted ErrorBox method as follows void ErrorBox (DWORD dwError, LPCSTR lpString) { #define MAX_MSG_BUF_SIZE 512 char *msgBuf; DWORD cMsgLen; cMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | 40, NULL, dwError, MAKELANGID(0, SUBLANG_ENGLISH_US), (LPTSTR) &msgBuf, MAX_MSG_BUF_SIZE, NULL); MessageBox( NULL, msgBuf, lpString, MB_OK ); LocalFree( msgBuf ); #undef MAX_MSG_BUF_SIZE it displays ... each and every time for a network printer ! The handle is invalid.
Ok, is the call to
FindFirstPrinterChangeNotification()
fine? What do the calls toOpenPrinter()
andWaitForSingleObject()
look like?
"The largest fire starts but with the smallest spark." - David Crow
-
Ok, is the call to
FindFirstPrinterChangeNotification()
fine? What do the calls toOpenPrinter()
andWaitForSingleObject()
look like?
"The largest fire starts but with the smallest spark." - David Crow
here is my code, I have taken out some debug strings, but the printername is valid as are the values of the handles returned. The code has been taken from the Microsoft Printmon example with just a few changes as I am using this in a class, hence the use of 'this' // setup printer name strcpy (pPrinterName, this->m_PrinterName); // open Printer, if access denied return ZeroMemory (&pd, sizeof (pd)); pd.DesiredAccess = PRINTER_ACCESS_USE; if((nReturn = OpenPrinter (pPrinterName, &hPrinter, &pd)) == ERROR_ACCESS_DENIED) return FALSE; // initialize local copy of the printer queue data ZeroMemory (&Queue, sizeof(Queue)); Queue.Printer.hPrinter = hPrinter; GetQueue (&Queue); // prepare for notifications, we want when a job is added, check for an error hPrinterNotification = FindFirstPrinterChangeNotification (hPrinter, PRINTER_CHANGE_JOB, 0, &NotificationOptions); if (hPrinterNotification == INVALID_HANDLE_VALUE) return 0; Queue.Printer.hPrinterNotification = hPrinterNotification; // loop while we are stilling waiting on Notifications while (Queue.Printer.hPrinterNotification != INVALID_HANDLE_VALUE) { if (WaitForSingleObject (Queue.Printer.hPrinterNotification, INFINITE) == WAIT_OBJECT_0) { // get the changes and reset the notification if (!FindNextPrinterChangeNotification (Queue.Printer.hPrinterNotification, &dwWaitResult, &NotificationOptions, (void **)&pNotification)) { ErrorBox(GetLastError(), "FindNextPrinterChangeNotification ...failed\r\n"); } Note also that the Printmon example also fails at the FindNextPrinterChange call with an invalid handle when the printer is a network one, so the error is consistent.
-
You seem to have missed the point ... I know openprinter returns a handle which is then used by FindFirstPrinterChangeNotification which itself returns a handle which is then used by the FindNextPrinterChangeNotification api. I've written out several items including the handle values, which are correct and don't change between the FindFirst and FindNext calls, but the FindNext call always errors with an invalid handle - but why with network printers ?
Did u get the answer for this...if yes please post it ...
-
Did u get the answer for this...if yes please post it ...
Sorry no never got it working, abandoned the project a year or so ago.
-
Sorry no never got it working, abandoned the project a year or so ago.
Hey finally got the fix for this... open windows firewall(run->firewall.cpl) open advanced tab and check file and printer sharing option Let me know if you face any problem with this...
-
Hey finally got the fix for this... open windows firewall(run->firewall.cpl) open advanced tab and check file and printer sharing option Let me know if you face any problem with this...