use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1 in project jna by java-native-access.
the class WinspoolUtil method getPrinterInfo1.
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());
}
use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1 in project jna by java-native-access.
the class WinspoolTest method testEnumPrinters_1.
public void testEnumPrinters_1() {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
// if there are no printers installed, EnumPrinters will succeed with zero items returned
Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 1, null, 0, pcbNeeded, pcReturned);
assertTrue(pcReturned.getValue() == 0);
if (pcbNeeded.getValue() > 0) {
PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue());
assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
assertTrue(pcReturned.getValue() >= 0);
PRINTER_INFO_1[] printerInfo = (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
for (PRINTER_INFO_1 pi : printerInfo) {
assertTrue(pi.pName == null || pi.pName.length() >= 0);
}
}
}
Aggregations