use of com.sun.jna.platform.win32.WinDef.LONG in project jna by java-native-access.
the class Advapi32Util method registrySetLongValue.
/**
* Set a long value in registry.
*
* @param root
* Root key.
* @param keyPath
* Path to an existing registry key.
* @param name
* Value name.
* @param value
* Value to write to registry.
*/
public static void registrySetLongValue(HKEY root, String keyPath, String name, long value) {
HKEYByReference phkKey = new HKEYByReference();
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
try {
registrySetLongValue(phkKey.getValue(), name, value);
} finally {
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
}
}
use of com.sun.jna.platform.win32.WinDef.LONG in project jna by java-native-access.
the class Kernel32Test method testGetSystemTimes.
public void testGetSystemTimes() {
Kernel32 kernel = Kernel32.INSTANCE;
FILETIME lpIdleTime = new FILETIME();
FILETIME lpKernelTime = new FILETIME();
FILETIME lpUserTime = new FILETIME();
boolean succ = kernel.GetSystemTimes(lpIdleTime, lpKernelTime, lpUserTime);
assertTrue(succ);
long idleTime = lpIdleTime.toDWordLong().longValue();
long kernelTime = lpKernelTime.toDWordLong().longValue();
long userTime = lpUserTime.toDWordLong().longValue();
// All should be >= 0. kernel includes idle.
assertTrue(idleTime >= 0);
assertTrue(kernelTime >= idleTime);
assertTrue(userTime >= 0);
}
use of com.sun.jna.platform.win32.WinDef.LONG in project jna by java-native-access.
the class Kernel32Test method testGetProcessList.
public void testGetProcessList() throws IOException {
HANDLE processEnumHandle = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL, new WinDef.DWORD(0));
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(processEnumHandle));
try {
Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
assertTrue(Kernel32.INSTANCE.Process32First(processEnumHandle, processEntry));
List<Long> processIdList = new ArrayList<Long>();
processIdList.add(processEntry.th32ProcessID.longValue());
while (Kernel32.INSTANCE.Process32Next(processEnumHandle, processEntry)) {
processIdList.add(processEntry.th32ProcessID.longValue());
}
assertTrue(processIdList.size() > 4);
} finally {
Kernel32Util.closeHandle(processEnumHandle);
}
}
use of com.sun.jna.platform.win32.WinDef.LONG in project jna by java-native-access.
the class WevtapiTest method testEvtCreateBookmark.
public void testEvtCreateBookmark() throws Exception {
EVT_HANDLE queryHandle = null;
EVT_HANDLE contextHandle = null;
File testEvtx = new File(getClass().getResource("/res/WevtapiTest.sample1.evtx").toURI());
StringBuilder sb = new StringBuilder();
try {
queryHandle = Wevtapi.INSTANCE.EvtQuery(null, testEvtx.getPath(), null, Winevt.EVT_QUERY_FLAGS.EvtQueryFilePath);
// test EvtCreateBookmark
EVT_HANDLE hBookmark = Wevtapi.INSTANCE.EvtCreateBookmark("<BookmarkList><Bookmark Channel='" + testEvtx.getAbsolutePath() + "' RecordId='" + 11 + "' IsCurrent='true'/></BookmarkList>");
if (hBookmark == null) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
// test EvtSeek
if (!Wevtapi.INSTANCE.EvtSeek(queryHandle, 0L, hBookmark, 0, Winevt.EVT_SEEK_FLAGS.EvtSeekRelativeToBookmark)) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
String[] targets = { "Event/System/EventRecordID" };
contextHandle = Wevtapi.INSTANCE.EvtCreateRenderContext(targets.length, targets, Winevt.EVT_RENDER_CONTEXT_FLAGS.EvtRenderContextValues);
int eventArraySize = 10;
int evtNextTimeout = 1000;
int arrayIndex = 1;
Memory buff;
IntByReference propertyCount = new IntByReference();
Winevt.EVT_VARIANT evtVariant = new Winevt.EVT_VARIANT();
EVT_HANDLE[] eventArray = new EVT_HANDLE[eventArraySize];
IntByReference returned = new IntByReference();
while (Wevtapi.INSTANCE.EvtNext(queryHandle, eventArraySize, eventArray, evtNextTimeout, 0, returned)) {
for (int i = 0; i < returned.getValue(); i++) {
EVT_HANDLE evtHandle = eventArray[i];
try {
buff = WevtapiUtil.EvtRender(contextHandle, eventArray[i], Winevt.EVT_RENDER_FLAGS.EvtRenderEventValues, propertyCount);
useMemory(evtVariant, buff, 0);
assertThat("EventRecordID", (Long) evtVariant.getValue(), is((long) arrayIndex * eventArraySize + i + 1));
sb.append(evtVariant.getValue());
// test EvtUpdateBookmark
if (!Wevtapi.INSTANCE.EvtUpdateBookmark(hBookmark, eventArray[i])) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
} finally {
if (eventArray[i] != null) {
Wevtapi.INSTANCE.EvtClose(eventArray[i]);
}
}
}
arrayIndex++;
}
if (Kernel32.INSTANCE.GetLastError() != WinError.ERROR_SUCCESS && Kernel32.INSTANCE.GetLastError() != WinError.ERROR_NO_MORE_ITEMS) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
buff = WevtapiUtil.EvtRender(null, hBookmark, Winevt.EVT_RENDER_FLAGS.EvtRenderBookmark, propertyCount);
assertThat(buff.getWideString(0), is("<BookmarkList>\r\n <Bookmark Channel='" + testEvtx.getAbsolutePath() + "' RecordId='" + 20 + "' IsCurrent='true'/>\r\n</BookmarkList>"));
assertThat(sb.length() > 0, is(true));
} finally {
if (queryHandle != null) {
Wevtapi.INSTANCE.EvtClose(queryHandle);
}
if (contextHandle != null) {
Wevtapi.INSTANCE.EvtClose(contextHandle);
}
}
}
use of com.sun.jna.platform.win32.WinDef.LONG in project jna by java-native-access.
the class WinNTTypesTest method testLargeIntegerUnionLongValue.
@Test
public void testLargeIntegerUnionLongValue() {
for (long expected : new long[] { Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, Short.MAX_VALUE, Byte.MAX_VALUE }) {
LARGE_INTEGER large = new LARGE_INTEGER(expected);
assertEquals("Mismatched large value", expected, large.getValue());
LARGE_INTEGER.LowHigh loHi = new LARGE_INTEGER.LowHigh(expected);
assertEquals("Mismatched low part", loHi.LowPart, large.getLow());
assertEquals("Mismatched high part", loHi.HighPart, large.getHigh());
}
}
Aggregations