Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug in WinspoolUtil.getPrinterInfo1() and WinspoolUtil.getPrint…

…erInfo4() where the first element's fields was never populated
  • Loading branch information...
commit cbc16d2a48b7320d1043acf412521b9231220aa8 1 parent 636b01b
unknown authored
Showing with 41 additions and 36 deletions.
  1. +41 −36 contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java
View
77 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());
+ }
}

0 comments on commit cbc16d2

Please sign in to comment.
Something went wrong with that request. Please try again.