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