use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_4 in project jna by java-native-access.
the class WinspoolTest method testEnumPrinters_4.
public void testEnumPrinters_4() {
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, 4, null, 0, pcbNeeded, pcReturned);
assertTrue(pcReturned.getValue() == 0);
if (pcbNeeded.getValue() > 0) {
PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue());
assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
assertTrue(pcReturned.getValue() >= 0);
PRINTER_INFO_4[] printerInfo = (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue());
for (PRINTER_INFO_4 pi : printerInfo) {
assertTrue(pi.pPrinterName == null || pi.pPrinterName.length() >= 0);
}
}
}
use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_4 in project jna by java-native-access.
the class WinspoolUtil method getPrinterInfo4.
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());
}
Aggregations