use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class User32Test method testGetLastInputInfo.
@Test
public void testGetLastInputInfo() throws Exception {
LASTINPUTINFO plii = new LASTINPUTINFO();
assertEquals(plii.size(), plii.cbSize);
assertTrue(User32.INSTANCE.GetLastInputInfo(plii));
assertTrue(Kernel32.INSTANCE.GetTickCount() >= plii.dwTime);
assertTrue(plii.dwTime > 0);
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class VariantTest method testVariantDate.
public void testVariantDate() {
SYSTEMTIME lpSystemTime = new SYSTEMTIME();
Kernel32.INSTANCE.GetLocalTime(lpSystemTime);
DoubleByReference pvtime = new DoubleByReference();
OleAuto.INSTANCE.SystemTimeToVariantTime(lpSystemTime, pvtime);
VARIANT variantDate = new VARIANT(new DATE(pvtime.getValue()));
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class OleAutoTest method testLoadRegTypeLib.
public void testLoadRegTypeLib() {
CLSID.ByReference clsid = new CLSID.ByReference();
// get CLSID from string, Microsoft Scripting Engine
HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString("{420B2830-E718-11CF-893D-00A0C9054228}"), clsid);
COMUtils.checkRC(hr);
assertEquals(0, hr.intValue());
// get user default lcid
LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
PointerByReference pWordTypeLib = new PointerByReference();
// get typelib version 1.0
hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, 1, 0, lcid, pWordTypeLib);
COMUtils.checkRC(hr);
assertEquals(0, hr.intValue());
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class PsapiTest method testGetProcessImageFileName.
@Test
public void testGetProcessImageFileName() {
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);
char[] buffer = new char[256];
Psapi.INSTANCE.GetProcessImageFileName(me, buffer, 256);
String path = new String(buffer);
assertTrue("Image path should contain 'java' and '.exe'", path.contains("java") && path.contains(".exe"));
} 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;
}
}
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class PsapiTest method testEnumProcessModules.
@Test
public void testEnumProcessModules() {
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);
} 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