Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FindNextPrinterChangeNotification - Invalid Handle

FindNextPrinterChangeNotification - Invalid Handle

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminc++jsontutorialquestion
14 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    P Gibson
    wrote on last edited by
    #1

    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 ?

    N D 2 Replies Last reply
    0
    • P P Gibson

      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 ?

      N Offline
      N Offline
      NiceNaidu fo
      wrote on last edited by
      #2

      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."

      N 1 Reply Last reply
      0
      • N NiceNaidu fo

        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."

        N Offline
        N Offline
        NiceNaidu fo
        wrote on last edited by
        #3

        Check this sample . http://msdn2.microsoft.com/en-us/library/54z247f9.aspx[^] Appu.. "If you judge people, you have no time to love them."

        P 1 Reply Last reply
        0
        • N NiceNaidu fo

          Check this sample . http://msdn2.microsoft.com/en-us/library/54z247f9.aspx[^] Appu.. "If you judge people, you have no time to love them."

          P Offline
          P Offline
          P Gibson
          wrote on last edited by
          #4

          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.

          N 1 Reply Last reply
          0
          • P P Gibson

            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.

            N Offline
            N Offline
            NiceNaidu fo
            wrote on last edited by
            #5

            Use the Handle returned by OpenPrinter , as the input Handle for FindNextPrinterChangeNotification Appu.. "If you judge people, you have no time to love them."

            P 1 Reply Last reply
            0
            • N NiceNaidu fo

              Use the Handle returned by OpenPrinter , as the input Handle for FindNextPrinterChangeNotification Appu.. "If you judge people, you have no time to love them."

              P Offline
              P Offline
              P Gibson
              wrote on last edited by
              #6

              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 ?

              U 1 Reply Last reply
              0
              • P P Gibson

                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 ?

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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 1 Reply Last reply
                0
                • D 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

                  P Offline
                  P Offline
                  pgibson007700
                  wrote on last edited by
                  #8

                  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.

                  D 1 Reply Last reply
                  0
                  • P pgibson007700

                    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.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Ok, is the call to FindFirstPrinterChangeNotification() fine? What do the calls to OpenPrinter() and WaitForSingleObject() look like?


                    "The largest fire starts but with the smallest spark." - David Crow

                    P 1 Reply Last reply
                    0
                    • D David Crow

                      Ok, is the call to FindFirstPrinterChangeNotification() fine? What do the calls to OpenPrinter() and WaitForSingleObject() look like?


                      "The largest fire starts but with the smallest spark." - David Crow

                      P Offline
                      P Offline
                      pgibson007700
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • P P Gibson

                        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 ?

                        U Offline
                        U Offline
                        User 4520583
                        wrote on last edited by
                        #11

                        Did u get the answer for this...if yes please post it ...

                        P 1 Reply Last reply
                        0
                        • U User 4520583

                          Did u get the answer for this...if yes please post it ...

                          P Offline
                          P Offline
                          pgibson007700
                          wrote on last edited by
                          #12

                          Sorry no never got it working, abandoned the project a year or so ago.

                          U 1 Reply Last reply
                          0
                          • P pgibson007700

                            Sorry no never got it working, abandoned the project a year or so ago.

                            U Offline
                            U Offline
                            User 4520583
                            wrote on last edited by
                            #13

                            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...

                            H 1 Reply Last reply
                            0
                            • U User 4520583

                              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...

                              H Offline
                              H Offline
                              honohsu
                              wrote on last edited by
                              #14

                              hi,I have got this problem, The situation is I have close my firewall, and the printer is a network printer when I look up the property of the printer, its port is USB002, so, I don't know how to fix it, can anyone help?

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups