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