This code gets the printer name right, but no matter if I pull the trays out, it still reports printer status 0. "Meaning ready"
I want to run my program on automatic, to print reports all night
When I am not there, but If it is out of paper, I wish to stop printing, I want to know what has been really printed.


long GetPrinterStatus (void)
{
unsigned long dwNeeded, dwReturned;
// HDC hdc ;
PRINTER_INFO_2 * pinfo2 ;
// PRINTER_INFO_6 * pinfo6 ;
long x;


if (GetVersion () & 0x80000000 || GetVersion () == 0xC0005A04 ) // Windows 98 || ME
{
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 2, NULL,0, &dwNeeded, &dwReturned) ;

OpenPrinter( pinfo5->pPrinterName, &hdc, 0 );

GetPrinter( hdc,2,0, 0, &dwNeeded );

pinfo2 = ( PRINTER_INFO_2 * ) malloc (dwNeeded) ;

EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 2, (PBYTE) pinfo2, dwNeeded, &dwNeeded, &dwReturned) ;


GetPrinter( hdc,2,(LPBYTE) pinfo2, dwNeeded, &dwNeeded );

x = pinfo2->Status;

}
else // Windows NT
{
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwNeeded, &dwReturned) ;

OpenPrinter( pinfo4->pPrinterName, &hdc, 0 );

GetPrinter( hdc,2,0, 0, &dwNeeded );

pinfo2 = ( PRINTER_INFO_2 * ) malloc (dwNeeded) ;


EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 2, (PBYTE) pinfo2, dwNeeded, &dwNeeded, &dwReturned) ;

GetPrinter( hdc,2,(LPBYTE) pinfo2, dwNeeded, &dwNeeded );

x = pinfo2->Status;

}
return x;
}