Updated getLastErrorMessage to use JNA library method instead of own.
This commit is contained in:
parent
0e1e27977a
commit
1ac74d0d08
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package dorkbox.util.jna.windows;
|
||||
|
||||
import com.sun.jna.platform.win32.Kernel32Util;
|
||||
|
||||
public
|
||||
class GetLastErrorException extends RuntimeException {
|
||||
private static final long serialVersionUID = 3980497906900380359L;
|
||||
|
@ -23,7 +25,7 @@ class GetLastErrorException extends RuntimeException {
|
|||
|
||||
public
|
||||
GetLastErrorException() {
|
||||
message = Kernel32.getLastErrorMessage();
|
||||
message = Kernel32Util.getLastErrorMessage();
|
||||
}
|
||||
|
||||
public
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Kernel32Util;
|
||||
import com.sun.jna.platform.win32.WinGDI;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class HBITMAPWrap extends HBITMAP {
|
|||
|
||||
if (pointerToBits == null) {
|
||||
// the bitmap was invalid
|
||||
LoggerFactory.getLogger(HBITMAPWrap.class).error("The image was invalid", Kernel32.getLastErrorMessage());
|
||||
LoggerFactory.getLogger(HBITMAPWrap.class).error("The image was invalid", Kernel32Util.getLastErrorMessage());
|
||||
}
|
||||
else {
|
||||
Raster raster = buf.getData();
|
||||
|
|
|
@ -17,9 +17,8 @@ package dorkbox.util.jna.windows;
|
|||
|
||||
import static com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Kernel32Util;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
|
@ -69,26 +68,7 @@ class Kernel32 {
|
|||
|
||||
public static void ASSERT(final int returnValue, final String message) {
|
||||
// if returnValue == 0, throw assertion error
|
||||
assert returnValue != 0 : message + " : " + getLastErrorMessage();
|
||||
}
|
||||
|
||||
public static
|
||||
String getLastErrorMessage() {
|
||||
int errorCode = Native.getLastError();
|
||||
if (errorCode == 0) {
|
||||
return "ErrorCode: 0x0 [No Error]";
|
||||
} else {
|
||||
Memory memory = new Memory(1024);
|
||||
PointerByReference reference = new PointerByReference(memory);
|
||||
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, null, errorCode, 0, reference, (int) memory.size(), null);
|
||||
|
||||
String memoryMessage = reference.getPointer()
|
||||
.getWideString(0);
|
||||
memoryMessage = memoryMessage.trim();
|
||||
|
||||
return String.format("ErrorCode: 0x%08x [%s]", errorCode, memoryMessage);
|
||||
}
|
||||
assert returnValue != 0 : message + " : " + Kernel32Util.getLastErrorMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue