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. How to get the status of a USB printer.

How to get the status of a USB printer.

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 3 Posters 1 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.
  • A Offline
    A Offline
    ashwath2005
    wrote on last edited by
    #1

    Dear All, I am using the following code to get the printer status. BOOL bSuccess = FALSE; char *pPrinterName = NULL; DWORD size = 0; GetDefaultPrinter(pPrinterName, &size); pPrinterName = new char[size+1]; memset(pPrinterName,'\0',size+1); if(GetDefaultPrinter(pPrinterName, &size) == FALSE) { delete[]pPrinterName; return ; } PRINTER_DEFAULTS* pd=NULL; BOOL bOpen = OpenPrinter(pPrinterName, &hPrinter, pd); if(!bOpen) { delete[]pPrinterName; return; } delete [] pPrinterName; GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded); BOOL bSuccess = FALSE; PRINTER_INFO_2 *pPrinterInfo; pPrinterInfo=(PRINTER_INFO_2*)GlobalAlloc(GPTR,dwBytesNeeded); bSuccess = GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, dwBytesNeeded,&dwBytesReturned); if(bSuccess == FALSE) return FALSE; bSuccess=TRUE; if(pPrinterInfo->Status != 0) { if((pPrinterInfo->Status)&PRINTER_STATUS_BUSY) { ShowMessage("Printer is busy"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_DOOR_OPEN) { ShowMessage("Printer door is open"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_ERROR) { ShowMessage("Printer is in error state"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_INITIALIZING) { ShowMessage("Printer is initializing"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_IO_ACTIVE) { ShowMessage("Printer is in an active state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_MANUAL_FEED) { ShowMessage("Printer is in a manual feed state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NO_TONER) { ShowMessage("Printer is out of toner"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NOT_AVAILABLE) { ShowMessage("Printer not present"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_OFFLINE) { ShowMessage("Printer is offline"); bSuccess = FALSE; } if((pPrinterInfo->S

    J B 2 Replies Last reply
    0
    • A ashwath2005

      Dear All, I am using the following code to get the printer status. BOOL bSuccess = FALSE; char *pPrinterName = NULL; DWORD size = 0; GetDefaultPrinter(pPrinterName, &size); pPrinterName = new char[size+1]; memset(pPrinterName,'\0',size+1); if(GetDefaultPrinter(pPrinterName, &size) == FALSE) { delete[]pPrinterName; return ; } PRINTER_DEFAULTS* pd=NULL; BOOL bOpen = OpenPrinter(pPrinterName, &hPrinter, pd); if(!bOpen) { delete[]pPrinterName; return; } delete [] pPrinterName; GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded); BOOL bSuccess = FALSE; PRINTER_INFO_2 *pPrinterInfo; pPrinterInfo=(PRINTER_INFO_2*)GlobalAlloc(GPTR,dwBytesNeeded); bSuccess = GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, dwBytesNeeded,&dwBytesReturned); if(bSuccess == FALSE) return FALSE; bSuccess=TRUE; if(pPrinterInfo->Status != 0) { if((pPrinterInfo->Status)&PRINTER_STATUS_BUSY) { ShowMessage("Printer is busy"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_DOOR_OPEN) { ShowMessage("Printer door is open"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_ERROR) { ShowMessage("Printer is in error state"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_INITIALIZING) { ShowMessage("Printer is initializing"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_IO_ACTIVE) { ShowMessage("Printer is in an active state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_MANUAL_FEED) { ShowMessage("Printer is in a manual feed state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NO_TONER) { ShowMessage("Printer is out of toner"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NOT_AVAILABLE) { ShowMessage("Printer not present"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_OFFLINE) { ShowMessage("Printer is offline"); bSuccess = FALSE; } if((pPrinterInfo->S

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      0 might be a valid return for "normal/online/ready" status.  You can check by intentionally "breaking" the printer by taking it offline, removing paper from it, opening it up, etc., and see if the status value changes accordingly.    Peace! -=- James


      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      DeleteFXPFiles & CheckFavorites (Please rate this post!)

      A 1 Reply Last reply
      0
      • J James R Twine

        0 might be a valid return for "normal/online/ready" status.  You can check by intentionally "breaking" the printer by taking it offline, removing paper from it, opening it up, etc., and see if the status value changes accordingly.    Peace! -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        A Offline
        A Offline
        ashwath2005
        wrote on last edited by
        #3

        hi, I have checked all those conditions but it does not work.I am using Windows XP machine.Should i install any service pack for this.

        1 Reply Last reply
        0
        • A ashwath2005

          Dear All, I am using the following code to get the printer status. BOOL bSuccess = FALSE; char *pPrinterName = NULL; DWORD size = 0; GetDefaultPrinter(pPrinterName, &size); pPrinterName = new char[size+1]; memset(pPrinterName,'\0',size+1); if(GetDefaultPrinter(pPrinterName, &size) == FALSE) { delete[]pPrinterName; return ; } PRINTER_DEFAULTS* pd=NULL; BOOL bOpen = OpenPrinter(pPrinterName, &hPrinter, pd); if(!bOpen) { delete[]pPrinterName; return; } delete [] pPrinterName; GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded); BOOL bSuccess = FALSE; PRINTER_INFO_2 *pPrinterInfo; pPrinterInfo=(PRINTER_INFO_2*)GlobalAlloc(GPTR,dwBytesNeeded); bSuccess = GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, dwBytesNeeded,&dwBytesReturned); if(bSuccess == FALSE) return FALSE; bSuccess=TRUE; if(pPrinterInfo->Status != 0) { if((pPrinterInfo->Status)&PRINTER_STATUS_BUSY) { ShowMessage("Printer is busy"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_DOOR_OPEN) { ShowMessage("Printer door is open"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_ERROR) { ShowMessage("Printer is in error state"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_INITIALIZING) { ShowMessage("Printer is initializing"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_IO_ACTIVE) { ShowMessage("Printer is in an active state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_MANUAL_FEED) { ShowMessage("Printer is in a manual feed state"); bSuccess = TRUE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NO_TONER) { ShowMessage("Printer is out of toner"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_NOT_AVAILABLE) { ShowMessage("Printer not present"); bSuccess = FALSE; } if((pPrinterInfo->Status)&PRINTER_STATUS_OFFLINE) { ShowMessage("Printer is offline"); bSuccess = FALSE; } if((pPrinterInfo->S

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          I ran into similar issues with a serial port printer and one connected to the parallel port. It turns out all 'suggestions' I discovered at Microsoft or on the Internet pointed to writing a 'printer monitor' type of driver. The notion was that the actual 'status' did not 'percolate' all the way up to this function call which should OBVIOUSLY be receiving the status. So, what I am trying to say is that I don't think your problem is specific only to the USB printer. People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

          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