

![]() | 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: [jna-users] Re: GetlastError alwa...| 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: [jna-users] Re: GetlastError always returns 0 | Actions... |
|---|---|---|
| From: | Kim Valentine (km_v...@yahoo.co.uk) | |
| Date: | Aug 8, 2007 7:02:16 am | |
| List: | net.java.dev.jna.users | |
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.
Rgds
Kim
Thomas Börkel <tho...@boerkel.de> wrote: HI!
I am too struggling with GetLastError().
I am not using the Kernel32 class from the examples, but my own. I tried to define the return type as NativeLong and as int with no difference. I always get 0 from GetLastError(), where I get for example "5" in C.
Relevant bits:
Java: Pointer handle; handle = getServiceHandle("localhost", WINNT.GENERIC_EXECUTE);
public static Pointer getServiceHandle(String machine, long access) throws Exception { Pointer handle; Advapi32 advapi32; WString machineW; NativeLong accessNL; int lastError;
advapi32 = Advapi32.INSTANCE;
machineW = new WString(machine); accessNL = new NativeLong(access); Kernel32.INSTANCE.GetLastError(); handle = advapi32.OpenSCManagerW(machineW, null, accessNL); lastError = Kernel32.INSTANCE.GetLastError();
if(handle == null) { throw new Exception("Win32 error: " + lastError); } return(handle); }
C: printf("%ld\n", OpenSCManagerW(L"localhost", NULL, GENERIC_EXECUTE)); printf("%ld\n", GetLastError());
Thanks!
Thomas
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net
--------------------------------- Yahoo! Answers - Get better answers from someone who knows. Tryit now.







