Windows spooler API GetPrinter() is not returning struct PRINTER_INFO_6 properly filled

0

I'm using Printer Spooling API to retrive the printer status information PRINTER_INFO_6 using GetPrinter() function.

Strangely, regardless of printer status, dwStatus member is always zero.

The following code retrieves the printer status information from the default printer and displays it on the screen:

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>


int main( void )
{
    HANDLE hPrinter = INVALID_HANDLE_VALUE;
    PPRINTER_INFO_6 pInfo = NULL;
    DWORD dwNeeded = 0L;
    CHAR szPrinterName[ MAX_PATH + 1 ] = {0};
    DWORD dwLength = MAX_PATH;
    BOOL ret = FALSE;


    ret = GetDefaultPrinter( szPrinterName, &dwLength );

    if( ret == FALSE )
    {
        fprintf(stderr, "[FATAL] GetDefaultPrinter() failed: %lu\n", GetLastError() );
        return EXIT_FAILURE;
    }

    ret = OpenPrinter( szPrinterName, &hPrinter, NULL );

    if( ret == FALSE )
    {
        fprintf(stderr, "[FATAL] OpenPrinter( '%s' ) failed: %lu\n", szPrinterName, GetLastError() );
        return EXIT_FAILURE;
    }

    GetPrinter( hPrinter, 6, NULL, 0, &dwNeeded );

    if(!dwNeeded)
    {
        fprintf(stderr, "[FATAL] GetPrinter() failed: %lu\n", GetLastError() );
        ClosePrinter( hPrinter );
        return EXIT_FAILURE;
    }

    pInfo = (PRINTER_INFO_6*) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwNeeded );

    if( pInfo == NULL )
    {
        fprintf(stderr, "[FATAL] HeapAlloc() failed: %lu\n", GetLastError() );
        ClosePrinter( hPrinter );
        return EXIT_FAILURE;
    }

    ret = GetPrinter( hPrinter, 6, (LPBYTE) pInfo, dwNeeded, &dwNeeded );

    if( ret == FALSE )
    {
        fprintf(stderr, "[FATAL] GetPrinter() failed: %lu\n", GetLastError() );
        HeapFree( GetProcessHeap(), 0, pInfo );
        ClosePrinter( hPrinter );
        return EXIT_FAILURE;
    }

    fprintf( stdout, "pInfo->dwStatus: 0x%08lX\n", pInfo->dwStatus );

    HeapFree( GetProcessHeap(), 0, pInfo );
    ClosePrinter( hPrinter );
    return EXIT_SUCCESS;
}

In the code above, pInfo->dwStatus is always 0x00000000.

Could someone tell me what's wrong? Clues?

c
windows
winapi
printing
asked on Stack Overflow Jun 5, 2019 by Lacobus

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0