Search in sources :

Example 46 with Kernel32

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);
}
Also used : OSVERSIONINFO(com.sun.jna.platform.win32.WinNT.OSVERSIONINFO)

Example 47 with Kernel32

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);
        }
    }
}
Also used : DWORD(com.sun.jna.platform.win32.WinDef.DWORD) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 48 with Kernel32

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);
}
Also used : DWORD(com.sun.jna.platform.win32.WinDef.DWORD) IntByReference(com.sun.jna.ptr.IntByReference) ShortByReference(com.sun.jna.ptr.ShortByReference) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference)

Example 49 with Kernel32

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
    }
}
Also used : SYSTEM_INFO(com.sun.jna.platform.win32.WinBase.SYSTEM_INFO)

Example 50 with Kernel32

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);
}
Also used : SIZE_T(com.sun.jna.platform.win32.BaseTSD.SIZE_T) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) MEMORY_BASIC_INFORMATION(com.sun.jna.platform.win32.WinNT.MEMORY_BASIC_INFORMATION)

Aggregations

HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)74 IntByReference (com.sun.jna.ptr.IntByReference)47 File (java.io.File)33 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)30 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)27 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)26 Memory (com.sun.jna.Memory)25 PointerByReference (com.sun.jna.ptr.PointerByReference)14 Pointer (com.sun.jna.Pointer)12 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)7 Test (org.junit.Test)7 SYSTEMTIME (com.sun.jna.platform.win32.WinBase.SYSTEMTIME)6 ArrayList (java.util.ArrayList)6 FILETIME (com.sun.jna.platform.win32.WinBase.FILETIME)5 HMODULE (com.sun.jna.platform.win32.WinDef.HMODULE)5 PSID (com.sun.jna.platform.win32.WinNT.PSID)5 TOKEN_PRIVILEGES (com.sun.jna.platform.win32.WinNT.TOKEN_PRIVILEGES)5 WString (com.sun.jna.WString)4 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)4 ShortByReference (com.sun.jna.ptr.ShortByReference)4