use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Kernel32Test method testGetVersionEx_OSVERSIONINFO.
public void testGetVersionEx_OSVERSIONINFO() {
OSVERSIONINFO lpVersionInfo = new OSVERSIONINFO();
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
assertTrue(Kernel32.INSTANCE.GetVersionEx(lpVersionInfo));
assertTrue(lpVersionInfo.dwMajorVersion.longValue() > 0);
assertTrue(lpVersionInfo.dwMinorVersion.longValue() >= 0);
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
assertTrue(lpVersionInfo.dwPlatformId.longValue() > 0);
assertTrue(lpVersionInfo.dwBuildNumber.longValue() > 0);
assertTrue(Native.toString(lpVersionInfo.szCSDVersion).length() >= 0);
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Kernel32Test method testSetCommTimeouts.
public void testSetCommTimeouts() {
WinBase.COMMTIMEOUTS lpCommTimeouts = new WinBase.COMMTIMEOUTS();
// Here we test a com port that definitely does not exist!
HANDLE handleSerialPort = Kernel32.INSTANCE.CreateFile("\\\\.\\comDummy", WinNT.GENERIC_READ | WinNT.GENERIC_WRITE, 0, null, WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
int lastError = Kernel32.INSTANCE.GetLastError();
assertEquals(lastError, WinNT.ERROR_FILE_NOT_FOUND);
// try to store the com port timeouts using the invalid handle
assertFalse(Kernel32.INSTANCE.SetCommTimeouts(handleSerialPort, lpCommTimeouts));
// Check if we can open a connection to com port1
// If yes, we try to store the com timeouts
// If no com port exists we have to skip this test
handleSerialPort = Kernel32.INSTANCE.CreateFile("\\\\.\\com1", WinNT.GENERIC_READ | WinNT.GENERIC_WRITE, 0, null, WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
lastError = Kernel32.INSTANCE.GetLastError();
if (WinNT.NO_ERROR == lastError) {
assertFalse(WinNT.INVALID_HANDLE_VALUE.equals(handleSerialPort));
try {
lpCommTimeouts = new WinBase.COMMTIMEOUTS();
assertTrue(Kernel32.INSTANCE.GetCommTimeouts(handleSerialPort, lpCommTimeouts));
DWORD oldReadIntervalTimeout = new DWORD(lpCommTimeouts.ReadIntervalTimeout.longValue());
lpCommTimeouts.ReadIntervalTimeout = new DWORD(20);
assertTrue(Kernel32.INSTANCE.SetCommTimeouts(handleSerialPort, lpCommTimeouts));
WinBase.COMMTIMEOUTS lpNewCommTimeouts = new WinBase.COMMTIMEOUTS();
assertTrue(Kernel32.INSTANCE.GetCommTimeouts(handleSerialPort, lpNewCommTimeouts));
assertEquals(20, lpNewCommTimeouts.ReadIntervalTimeout.intValue());
lpCommTimeouts.ReadIntervalTimeout = oldReadIntervalTimeout;
assertTrue(Kernel32.INSTANCE.SetCommTimeouts(handleSerialPort, lpCommTimeouts));
} finally {
Kernel32Util.closeHandle(handleSerialPort);
}
}
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Kernel32Test method testCreateProcess.
public void testCreateProcess() {
WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO();
WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReference();
boolean status = Kernel32.INSTANCE.CreateProcess(null, "cmd.exe /c echo hi", null, null, true, new WinDef.DWORD(0), Pointer.NULL, System.getProperty("java.io.tmpdir"), startupInfo, processInformation);
assertTrue(status);
assertTrue(processInformation.dwProcessId.longValue() > 0);
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Kernel32Test method testGetNativeSystemInfo.
public void testGetNativeSystemInfo() {
try {
SYSTEM_INFO lpSystemInfo = new SYSTEM_INFO();
Kernel32.INSTANCE.GetNativeSystemInfo(lpSystemInfo);
assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0);
} catch (UnsatisfiedLinkError e) {
// only available under WOW64
}
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Kernel32Test method testVirtualQueryEx.
public void testVirtualQueryEx() {
HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentProcess();
MEMORY_BASIC_INFORMATION mbi = new MEMORY_BASIC_INFORMATION();
SIZE_T bytesRead = Kernel32.INSTANCE.VirtualQueryEx(selfHandle, Pointer.NULL, mbi, new SIZE_T(mbi.size()));
assertTrue(bytesRead.intValue() > 0);
}
Aggregations