use of com.sun.jna.platform.win32.Win32Exception in project jna by java-native-access.
the class Advapi32UtilTest method registrySetEmptyValue.
private static void registrySetEmptyValue(HKEY root, String keyPath, String name, final int valueType) {
HKEYByReference phkKey = new HKEYByReference();
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
try {
char[] data = new char[0];
rc = Advapi32.INSTANCE.RegSetValueEx(phkKey.getValue(), name, 0, valueType, data, 0);
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
} finally {
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
}
}
use of com.sun.jna.platform.win32.Win32Exception 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.Win32Exception 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());
}
use of com.sun.jna.platform.win32.Win32Exception 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;
}
use of com.sun.jna.platform.win32.Win32Exception in project jna by java-native-access.
the class WinspoolUtil method getJobInfo1.
public static JOB_INFO_1[] getJobInfo1(HANDLEByReference phPrinter) {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, null, 0, pcbNeeded, pcReturned);
if (pcbNeeded.getValue() <= 0) {
return new JOB_INFO_1[0];
}
JOB_INFO_1 pJobEnum = new JOB_INFO_1(pcbNeeded.getValue());
if (!Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, pJobEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
pJobEnum.read();
return (JOB_INFO_1[]) pJobEnum.toArray(pcReturned.getValue());
}
Aggregations