Hi all,
the correct parameter for PrnStatus () is the printer name, not the port !
If specify a real printer name, the function returns 0 (PRINTER_STATUS_OK). But it does not return the real status of the printer. Windows can not get the correct status of a printer, if no jobs are in it´s queue.
This is what I found in the web about this issue:
To further complicate things, it turns out that Windows only queries the printer for its status when there's a print job for the it, which means that if you are not printing you probably can't find out the real printer status. If you are not concerned about this, you'll be glad to know that you can obtain the same information on WinNT and Win9x by querying the print job instead of the printer for the status, via the GetJob() api.
I think, windows should do the job, it´s not DOS anymore. Windows tells us, if there are errors while printing. In our applications it is enough to check if a printer exists or not.
This is a modified version of PrnStatus, which return a correct error code if the printer does not exist.
#define ERROR_INVALID_PRINTER_NAME Â 1801
FUNCTION CheckStatus (cPrinter)
LOCAL nStatus := PrinterStatus (cPrinter)
LOCAL cStatus := IIF (nStatus = ERROR_INVALID_PRINTER_NAME, ;
                "Invalid Printer name", STR (nStatus) )
RETURN (cStatus)
#pragma BEGINDUMP
#include <Windows.h>
#include <HbApi.h>
HB_FUNC ( PRINTERSTATUS ) // cPrinter or cPrinterServer --> nStatus
{
 HANDLE hPrinter = NULL;
 DWORD cBytesNeeded = 0, cBytesUsed = 0, pstatus = -1;
 PRINTER_INFO_2 * pPrinterInfo = NULL;
  if( OpenPrinter( hb_parc( 1 ), &hPrinter, NULL ) )
  {
   GetPrinter( hPrinter, 2, NULL, 0, &cBytesNeeded );
   pPrinterInfo = ( PRINTER_INFO_2 * ) hb_xgrab( cBytesNeeded );
   //cBytesUsed = cBytesNeeded;
   GetPrinter( hPrinter, 2, ( unsigned char * ) pPrinterInfo, cBytesNeeded, &cBytesUsed );
   pstatus = (pPrinterInfo->Status) ;
   hb_retnl( pPrinterInfo->Status ) ;
   hb_xfree( pPrinterInfo );
   ClosePrinter( hPrinter );
  }
  else
   hb_retnl( GetLastError() );  // return error code if Openprinter() fails
}