Код: Выделить всё
#include
int GetPrinterStatus( char* szPrnName )
{
HANDLE hHandle = 0; // Handle of the printer
DWORD dwStatus = 0; // Printer status we should receive
DWORD dwSize = 0; // Size of memory we should
// allocate for PRINTER_INFO_2
PRINTER_INFO_2* pPrnInfo2 = 0; // Structure specifies detailed
// printer information
DEVMODE DevMode = {0}; // Structure contains information
// about the device initialization
// and environment of a printer
PRINTER_DEFAULTS PrnDef = { 0, &DevMode, PRINTER_ACCESS_USE };
// Open printer with name szPrnName
if( !OpenPrinter( szPrnName, &hHandle, &PrnDef ) )
return -1; // Error
// How many memory should be allocated for printer data?
GetPrinter( hHandle, 2, 0, 0, &dwSize );
if( !dwSize )
{
ClosePrinter( hHandle );
return -1; // Error
}
// Allocate memory
pPrnInfo2 = (PRINTER_INFO_2*)malloc( dwSize );
// Receive printer details
if(!GetPrinter( hHandle, 2, (LPBYTE)pPrnInfo2, dwSize, &dwSize ))
{
ClosePrinter( hHandle );
free( pPrnInfo2 );
return -1; // Error
}
dwStatus = pPrnInfo2->Status;
// Free allocated memory
free( pPrnInfo2 );
// Close printer
ClosePrinter( hHandle );
return dwStatus;
}

Вот так:
Код: Выделить всё
int status = GetPrinterStatus("POS58");
Затем я попробовал заменить вызов OpenPrinter на OpenPrinter2W и использовать опцию PRINTER_OPTION_NO_CACHE, но это не помогло.
Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/414 ... ne-printer