I want to get the printer port status (online or offline) , so I use WIN32 API , But get error on "GetPrinter" : it is said the data buffer is too small .
What's wrong with the function ? Please help me . or any other way to get printer port status Please tell me .
bool NEAR PrintOnLpt1Ready()
{
HANDLE hPrinter ;
PRINTER_INFO_2 pPrinter ;
DWORD pcbNeeded ;
int i , OnPosition ;
char pName[255] ;
pcbNeeded = sizeof(PRINTER_INFO_2) ;
MessageBox(NULL,IntToStr(pcbNeeded).c_str(),"Size",MB_OK) ;
for (i=0 ; i<Printer()->Printers->Count ; i++)
{
strcpy(pName , Printer()->Printers->Strings[i].c_str()) ;
OnPosition = Printer()->Printers->Strings[i].Pos(" on") ;
pName[OnPosition-1] = '\0' ;
if (OpenPrinter(pName,&hPrinter,NULL)==true)
{
if (GetPrinter(hPrinter,2,(unsigned char *)&pPrinter,sizeof(PRINTER_INFO_2),&pcbNeeded)==true)
MessageBox(NULL,pName,pPrinter.pPortName,MB_OK) ;
ClosePrinter(hPrinter);
}
else
{
ShowLastError() ;
}
}
return(false);
}