Search in sources :

Example 1 with PRINTER_INFO_1

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());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PRINTER_INFO_1(com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1)

Example 2 with PRINTER_INFO_1

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);
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PRINTER_INFO_1(com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1)

Aggregations

PRINTER_INFO_1 (com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1)2 IntByReference (com.sun.jna.ptr.IntByReference)2