use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2 in project jna by java-native-access.
the class WinspoolTest method testEnumPrinters_2.
public void testEnumPrinters_2() {
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, 2, null, 0, pcbNeeded, pcReturned);
assertTrue(pcReturned.getValue() == 0);
if (pcbNeeded.getValue() > 0) {
PRINTER_INFO_2 pPrinterEnum = new PRINTER_INFO_2(pcbNeeded.getValue());
assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 2, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
assertTrue(pcReturned.getValue() >= 0);
PRINTER_INFO_2[] printerInfo = (PRINTER_INFO_2[]) pPrinterEnum.toArray(pcReturned.getValue());
for (PRINTER_INFO_2 pi : printerInfo) {
assertTrue(pi.pPrinterName == null || pi.pPrinterName.length() >= 0);
}
}
}
use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2 in project jna by java-native-access.
the class WinspoolUtil method getPrinterInfo2.
private static PRINTER_INFO_2[] getPrinterInfo2(int flags) {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
Winspool.INSTANCE.EnumPrinters(flags, null, 2, null, 0, pcbNeeded, pcReturned);
if (pcbNeeded.getValue() <= 0)
return new PRINTER_INFO_2[0];
PRINTER_INFO_2 pPrinterEnum = new PRINTER_INFO_2(pcbNeeded.getValue());
if (!Winspool.INSTANCE.EnumPrinters(flags, null, 2, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned))
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
pPrinterEnum.read();
return (PRINTER_INFO_2[]) pPrinterEnum.toArray(pcReturned.getValue());
}
use of com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2 in project jna by java-native-access.
the class WinspoolUtil method getPrinterInfo2.
public static PRINTER_INFO_2 getPrinterInfo2(String printerName) {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
HANDLEByReference pHandle = new HANDLEByReference();
if (!Winspool.INSTANCE.OpenPrinter(printerName, pHandle, null))
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
Win32Exception we = null;
PRINTER_INFO_2 pinfo2 = null;
try {
Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, null, 0, pcbNeeded);
if (pcbNeeded.getValue() <= 0)
return new PRINTER_INFO_2();
pinfo2 = new PRINTER_INFO_2(pcbNeeded.getValue());
if (!Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, pinfo2.getPointer(), pcbNeeded.getValue(), pcReturned))
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
pinfo2.read();
} catch (Win32Exception e) {
we = e;
} finally {
if (!Winspool.INSTANCE.ClosePrinter(pHandle.getValue())) {
Win32Exception ex = new Win32Exception(Kernel32.INSTANCE.GetLastError());
if (we != null) {
ex.addSuppressed(we);
}
}
}
if (we != null) {
throw we;
}
return pinfo2;
}
Aggregations