I want to check if printer is online. For this I get the printer handle with OpenPrinter. Then I want to use PRINTER_STATUS_OFFLINE in PRINTER_INFO_6 with GetPrinter(). The result is always 0?
How do I get the offline state of my printer?
Code I used.
bool IsPrinterOnline(wstring strPrinterFriendlyName)
{
HANDLE hPrinter ;
if ( OpenPrinter(const_cast<LPWSTR>(strPrinterFriendlyName.c_str()), &hPrinter, NULL) == 0 )
{
/*OpenPrinter call failed*/
return false;
}
DWORD dwBufsize = 0;
PRINTER_INFO_6* pinfo = 0;
GetPrinter(hPrinter, 6,(LPBYTE)pinfo, dwBufsize, &dwBufsize); //Get dwBufsize
PRINTER_INFO_6* pinfo6 = (PRINTER_INFO_6*)malloc(dwBufsize); //Allocate with dwBufsize
GetPrinter(hPrinter, 6,(LPBYTE)pinfo6, dwBufsize, &dwBufsize);
DWORD dwStatus = pinfo6->dwStatus; //always returns 0
if (dwStatus == PRINTER_STATUS_OFFLINE)
{
free(pinfo6);
ClosePrinter( hPrinter );
return false;
}
free(pinfo6);
ClosePrinter( hPrinter );
return true;
}
GetPrinter
actually succeed? – Quoit