

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
12 messages in net.java.dev.jna.usersRe: GetlastError always returns 0| From | Sent On | Attachments |
|---|---|---|
| Timothy Wall | Aug 7, 2007 7:52 am | |
| Thomas Börkel | Aug 8, 2007 5:15 am | |
| Timothy Wall | Aug 8, 2007 6:35 am | |
| Thomas Börkel | Aug 8, 2007 6:45 am | |
| Kim Valentine | Aug 8, 2007 7:02 am | |
| Timothy Wall | Aug 8, 2007 7:26 am | |
| Timothy Wall | Aug 8, 2007 7:34 am | |
| Timothy Wall | Aug 8, 2007 7:42 am | |
| Thomas Börkel | Aug 8, 2007 8:00 am | |
| Thomas Börkel | Aug 8, 2007 8:05 am | |
| Thomas Börkel | Aug 8, 2007 8:21 am | |
| Timothy Wall | Aug 8, 2007 8:50 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: GetlastError always returns 0 | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Aug 7, 2007 7:52:17 am | |
| List: | net.java.dev.jna.users | |
On Aug 7, 2007, at 8:46 AM, Kim Valentine wrote:
Timothy, I think you are correct, I was running the code in the Eclipse debugger, and I suspect that a JVM in debug does extra calls that destroy the last error. When I ran without debugging I usually got non zero from GetLastError, but there were still some occasions when I got zero. I found that I didnt need the extra DLL, and as long as you calll GetLastError once before any other call I usually got something. The Microsoft documentation says that GetLastError is thread specific, If I believe tht then it would mean that occasionally the JVM invokes extra Windows calls on the native thread. I was running in the default thread i.e. I hadnt started any threads explicitly, I might get a better result if I tried a specific thread for all JNA calls.
I found that even the following two lines differed:
assertEquals("message", 8, lib.GetLastError()); // fails
int err = lib.GetLastError(); assertEquals("message", 8, err); // success!
You'd have to look at the bytecode or the JIT results to see what exactly is being generated, but something in the first case winds up overwriting GetLastError. Make sure that you always capture the value of GetLastError *immediately* after the library call which sets it.
If for some reason that doesn't work on a consistent basis, we might look at auto-capturing GetLastError in some sort of post-invoke hook, but I'd want to figure out where the VM is stomping on the value first.
As you surmised, running under the debugger can cause all sorts of native stuff to happen as the VM negotiates with the debugger.
Sorry to respond to you directly but I cant work out how to get Yahoo Mail to reply to the thread Rgds Kim
Even if you can't reply directly to the thread, be sure to cc use...@jna.dev.java.net.







