On Jul 12, 2007, at 9:20 AM, Daniel Kaufmann wrote:
I couldn't test it at this time as I stopped using jna, but I am still
unable to get the last error code in windows.
Even calling SetLastError and then GetLastError is not working for
me. I
attach the test I run.
I'm not sure why SetLastError doesn't work, but if you call
GetLastError on startup, subsequent calls will work properly. The
following code works for me:
kernel.GetLastError();
if (kernel.GetProcessId(null) == 0) {
final int INVALID_HANDLE = 6;
assertEquals("Wrong error value", INVALID_HANDLE,
kernel.GetLastError());
}
I haven't tried in unix doing similar stuff, but my guess is you
will have
the same kind of problems with errno (I don't know if you can use
errno
directly in unix, but at least you should be able to use perror to
print the
error using errno value).
It would be nice if jna would provide a way to access this last
error codes,
with the value immediatly after the call to the native function.
errno is a global variable, not a function, so you wouldn't be able
to read it directly from jna unless the system provides a function-
call equivalent.