use of com.sun.jna.platform.win32.Psapi.MODULEINFO in project jna by java-native-access.
the class PsapiTest method testGetModuleInformation.
@Test
public void testGetModuleInformation() {
HANDLE me = null;
Win32Exception we = null;
try {
me = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, false, Kernel32.INSTANCE.GetCurrentProcessId());
assertTrue("Handle to my process should not be null", me != null);
List<HMODULE> list = new LinkedList<HMODULE>();
HMODULE[] lphModule = new HMODULE[100 * 4];
IntByReference lpcbNeeded = new IntByReference();
if (!Psapi.INSTANCE.EnumProcessModules(me, lphModule, lphModule.length, lpcbNeeded)) {
throw new Win32Exception(Native.getLastError());
}
for (int i = 0; i < lpcbNeeded.getValue() / 4; i++) {
list.add(lphModule[i]);
}
assertTrue("List should have at least 1 item in it.", list.size() > 0);
MODULEINFO lpmodinfo = new MODULEINFO();
if (!Psapi.INSTANCE.GetModuleInformation(me, list.get(0), lpmodinfo, lpmodinfo.size())) {
throw new Win32Exception(Native.getLastError());
}
assertTrue("MODULEINFO.EntryPoint should not be null.", lpmodinfo.EntryPoint != null);
} catch (Win32Exception e) {
we = e;
// re-throw to invoke finally block
throw we;
} finally {
try {
Kernel32Util.closeHandle(me);
} catch (Win32Exception e) {
if (we == null) {
we = e;
} else {
we.addSuppressed(e);
}
}
if (we != null) {
throw we;
}
}
}
Aggregations