On Aug 8, 2007, at 10:02 AM, Kim Valentine wrote:
Problem is that other calls to windows API's overwrite the error
code. I fund that the following helped
1. Before calling any Windows APIs that set the errorcode call
GetLastError, this ensires that jna has aet up the call.
2. Make sure that you retriere the error code immediately after the
suspect call.
3. Running the JVM in debug mode always seems to overwrite the
errorcode.
However even when I had followed all these guidelines I still find
that occasionally the errorcode is lost. This occurs in code within
a for loop, so the results are not detrministic.
I think that under some circumstances the JVM does extra windows
calls on the same native thread , but I dont know how to trap or
detect them.
I don't think there's a way to avoid VM operations which might
overwrite GetLastError, especially if you have any result conversion
or data buffer arguments, since the native code has to do some
copying of data. There are a number of cases where either the native
code or JNA library cannot avoid making some VM calls.
Ideally I'd like to track down the indeterminancy in obtaining the
result.
One way to fix this might be to sample the GetLastError value after
every function, or after functions declared with a particular method
signature (perhaps a "GetLastErrorException", which automatically
looks up and throws an exception when the failure result value is
encountered).