From cbc16d2a48b7320d1043acf412521b9231220aa8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jan 2012 09:18:24 +0100 Subject: [PATCH] Fixed bug in WinspoolUtil.getPrinterInfo1() and WinspoolUtil.getPrinterInfo4() where the first element's fields was never populated --- .../sun/jna/platform/win32/WinspoolUtil.java | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java index 1e3aa78bd6..58f9a32ec9 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java @@ -18,43 +18,48 @@ /** * Winspool Utility API. + * * @author dblock[at]dblock.org */ public abstract class WinspoolUtil { - - public static PRINTER_INFO_1[] getPrinterInfo1() { - IntByReference pcbNeeded = new IntByReference(); - IntByReference pcReturned = new IntByReference(); - Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, - null, 1, null, 0, pcbNeeded, pcReturned); - if (pcbNeeded.getValue() <= 0) { - return new PRINTER_INFO_1[0]; - } - - PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue()); - if(! Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, - null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } - - return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue()); - } - - public static PRINTER_INFO_4[] getPrinterInfo4() { - IntByReference pcbNeeded = new IntByReference(); - IntByReference pcReturned = new IntByReference(); - Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, - null, 4, null, 0, pcbNeeded, pcReturned); - if (pcbNeeded.getValue() <= 0) { - return new PRINTER_INFO_4[0]; - } - - PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue()); - if(! Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, - null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } - - return (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue()); - } + + public static PRINTER_INFO_1[] getPrinterInfo1() { + IntByReference pcbNeeded = new IntByReference(); + IntByReference pcReturned = new IntByReference(); + Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, + null, 1, null, 0, pcbNeeded, pcReturned); + if (pcbNeeded.getValue() <= 0) { + return new PRINTER_INFO_1[0]; + } + + PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue()); + if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, + null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { + throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); + } + + pPrinterEnum.read(); + + return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue()); + } + + public static PRINTER_INFO_4[] getPrinterInfo4() { + IntByReference pcbNeeded = new IntByReference(); + IntByReference pcReturned = new IntByReference(); + Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, + null, 4, null, 0, pcbNeeded, pcReturned); + if (pcbNeeded.getValue() <= 0) { + return new PRINTER_INFO_4[0]; + } + + PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue()); + if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, + null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { + throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); + } + + pPrinterEnum.read(); + + return (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue()); + } } \ No newline at end of file