Skip to content

Retrieving the last Win32 error #1114

@decce6

Description

@decce6

Question

Hello! my project Ixeris (a Minecraft mod) makes some calls to Win32 APIs. The bindings are generated with LWJGL's generator. I call WinBase.getLastError() immediately after a failed function invocation, but it seems to be returning 0 on latest LWJGL.

The code: https://github.com/decce6/Ixeris/blob/bc7550f93a93c686f5c881cc0d4cfd06b31e7d05/core/src/main/java/me/decce/ixeris/core/input/win32/RawInputHandlerWin32.java#L133-L136

I initially thought this might be due to changes in LWJGL 3.3.5, whose changelog wrote "The LibCErrno.getErrno() and WinBase.getLastError() methods have been removed.". However, this happens on 3.3.3 too. Interestingly, this doesn't happen on 3.2.2, where the correct error code is returned.
It appears that whether WinBase.getLastError() works depends on the JVM. From my testing, it works on Java 21 but not 25.

It seems the current preferred way of retrieving the error code is via a int buffer passed to the function. However, I'd like to avoid bundling native code, if possible. Is there a way to achieve that?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions