Problem in Getting the Printer Status
Posted on 2000-03-20
We are doing a VC++ applicatin in which we do a printing job also.
We need to find out the printer status before the data is sent to Printer. For that we are opening the printer and getting the printer handle. Then using the GetPrinter we are getting the printer info of level 2. But the status of the printer is always shown as 0 only irrespective of the printer status. We have tried opening all the tays of the printer. We have tried giving a printer device name which doent exist at all.
In all the cases the status is 0 only.
Please help us in this reagrd.
The sample code we are using is given below:
CString str = printDlg.GetDeviceName();
char* strName = str.GetBuffer(0);
if( !OpenPrinter(strName,&hPrintHandle,NULL) )
AfxMessageBox( "Error in opening the print...");
BOOL b = GetPrinter( hPrintHandle,2, NULL,0,&dwNeeded );
DWORD err = GetLastError();
dwNeeded = dwNeeded + 4;
printerInfo = (PRINTER_INFO_2 *)malloc(dwNeeded);
if (!(printerInfo)) /* Failure to allocate memory. */
/* Get the printer information. */
if (!GetPrinter(hPrintHandle, 2,(LPBYTE)printerInfo, dwNeeded,&cByteUsed) )
/* Failure to access the printer. */
printerInfo = NULL;
DWORD printerStatus = printerInfo->Status;//This value is always coming as 0
Thanks in advance