12 messages in net.java.dev.jna.usersRe: [jna-users] Re: GetlastError alwa...
FromSent OnAttachments
Timothy WallAug 7, 2007 7:52 am 
Thomas BörkelAug 8, 2007 5:15 am 
Timothy WallAug 8, 2007 6:35 am 
Thomas BörkelAug 8, 2007 6:45 am 
Kim ValentineAug 8, 2007 7:02 am 
Timothy WallAug 8, 2007 7:26 am 
Timothy WallAug 8, 2007 7:34 am 
Timothy WallAug 8, 2007 7:42 am 
Thomas BörkelAug 8, 2007 8:00 am 
Thomas BörkelAug 8, 2007 8:05 am 
Thomas BörkelAug 8, 2007 8:21 am 
Timothy WallAug 8, 2007 8:50 am 
Actions with this message:
Paste this link in email or IM:
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 0Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Aug 8, 2007 6:35:42 am
List:net.java.dev.jna.users

I'd guess that the construction of a Pointer with the return value (which causes object allocation) is causing the GetLastError value to be overwritten.

Try changing the return type to void to see if it makes a difference (I know that's not useful in actual usage, but it'll help determine if it's the allocation of the return value which clears the error).

T.

On Aug 8, 2007, at 8:16 AM, Thomas Börkel 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());