On Aug 8, 2007, at 9:45 AM, Thomas Börkel wrote:
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());
Here's my definition and usage, which returns nonzero for
GetLastError. I'm using the W32API default options, which uses wide
native strings (unicode) mapping for all java strings, and auto-maps
the function name to the "W" suffix:
public static interface Advapi32 extends W32API {
Advapi32 INSTANCE = (Advapi32)Native.loadLibrary("advapi32",
Advapi32.class, DEFAULT_OPTIONS);
Pointer OpenSCManager(String lpMachineName, String
lpDatabaseName, int dwDesiredAccess);
}
Pointer h = Advapi32.INSTANCE.OpenSCManager("localhost",
null, 0xF003F);
int code = kernel.GetLastError();
I'm running on XP.