Search in sources :

Example 21 with Kernel32

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);
}
Also used : LASTINPUTINFO(com.sun.jna.platform.win32.WinUser.LASTINPUTINFO) Test(org.junit.Test)

Example 22 with Kernel32

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()));
}
Also used : DoubleByReference(com.sun.jna.ptr.DoubleByReference) DATE(com.sun.jna.platform.win32.OaIdl.DATE) SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT)

Example 23 with Kernel32

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());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 24 with Kernel32

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

Example 25 with Kernel32

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;
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HMODULE(com.sun.jna.platform.win32.WinDef.HMODULE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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