diff --git a/windows/printing.c b/windows/printing.c index e6b3531d..0ec81376 100644 --- a/windows/printing.c +++ b/windows/printing.c @@ -67,11 +67,15 @@ static bool printer_add_enum(int param, DWORD level, char **buffer, /* * Exploratory call to EnumPrinters to determine how much space - * we'll need for the output. Discard the return value since it - * will almost certainly be a failure due to lack of space. + * we'll need for the output. + * + * If we get ERROR_INSUFFICIENT_BUFFER, that's fine, we're + * prepared to deal with it. Any other error, we return failure. */ - p_EnumPrinters(param, NULL, level, (LPBYTE)((*buffer)+offset), 512, - &needed, &nprinters); + if (p_EnumPrinters(param, NULL, level, (LPBYTE)((*buffer)+offset), 512, + &needed, &nprinters) == 0 && + GetLastError() != ERROR_INSUFFICIENT_BUFFER) + return false; if (needed < 512) needed = 512;