Search in sources :

Example 31 with DWORD

use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.

the class PdhTest method testQueryOneCounter.

@Test
public void testQueryOneCounter() {
    PDH_COUNTER_PATH_ELEMENTS elems = new PDH_COUNTER_PATH_ELEMENTS();
    elems.szObjectName = "Processor";
    elems.szInstanceName = "_Total";
    elems.szCounterName = "% Processor Time";
    String counterName = makeCounterPath(pdh, elems);
    HANDLEByReference ref = new HANDLEByReference();
    assertErrorSuccess("PdhOpenQuery", pdh.PdhOpenQuery(null, null, ref), true);
    HANDLE hQuery = ref.getValue();
    try {
        ref.setValue(null);
        assertErrorSuccess("PdhAddEnglishCounter", pdh.PdhAddEnglishCounter(hQuery, counterName, null, ref), true);
        HANDLE hCounter = ref.getValue();
        try {
            assertErrorSuccess("PdhCollectQueryData", pdh.PdhCollectQueryData(hQuery), true);
            DWORDByReference lpdwType = new DWORDByReference();
            PDH_RAW_COUNTER rawCounter = new PDH_RAW_COUNTER();
            assertErrorSuccess("PdhGetRawCounterValue", pdh.PdhGetRawCounterValue(hCounter, lpdwType, rawCounter), true);
            assertEquals("Bad counter data status", PdhMsg.PDH_CSTATUS_VALID_DATA, rawCounter.CStatus);
            DWORD dwType = lpdwType.getValue();
            int typeValue = dwType.intValue();
            // see https://technet.microsoft.com/en-us/library/cc786359(v=ws.10).aspx
            assertEquals("Mismatched counter type", WinPerf.PERF_100NSEC_TIMER_INV, typeValue);
            showRawCounterData(System.out, counterName, rawCounter);
        } finally {
            assertErrorSuccess("PdhRemoveCounter", pdh.PdhRemoveCounter(hCounter), true);
        }
    } finally {
        assertErrorSuccess("PdhCloseQuery", pdh.PdhCloseQuery(hQuery), true);
    }
}
Also used : PDH_COUNTER_PATH_ELEMENTS(com.sun.jna.platform.win32.Pdh.PDH_COUNTER_PATH_ELEMENTS) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) PDH_RAW_COUNTER(com.sun.jna.platform.win32.Pdh.PDH_RAW_COUNTER) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) Test(org.junit.Test)

Example 32 with DWORD

use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.

the class PdhTest method makeCounterPath.

private static String makeCounterPath(Pdh pdh, PDH_COUNTER_PATH_ELEMENTS pathElements) {
    DWORDByReference pcchBufferSize = new DWORDByReference();
    int status = pdh.PdhMakeCounterPath(pathElements, null, pcchBufferSize, 0);
    assertEquals("Unexpected status code: 0x" + Integer.toHexString(status), PdhMsg.PDH_MORE_DATA, status);
    DWORD bufSize = pcchBufferSize.getValue();
    int numChars = bufSize.intValue();
    assertTrue("Bad required buffer size: " + numChars, numChars > 0);
    char[] szFullPathBuffer = new char[numChars + 1];
    pcchBufferSize.setValue(new DWORD(szFullPathBuffer.length));
    assertErrorSuccess("PdhMakeCounterPath", pdh.PdhMakeCounterPath(pathElements, szFullPathBuffer, pcchBufferSize, 0), true);
    return Native.toString(szFullPathBuffer);
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 33 with DWORD

use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.

the class Shell32Test method newAppBar.

private void newAppBar() {
    APPBARDATA data = new APPBARDATA.ByReference();
    data.cbSize.setValue(data.size());
    data.uCallbackMessage.setValue(WM_USER + 1);
    UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_NEW), data);
    assertNotNull(result);
}
Also used : DWORD(com.sun.jna.platform.win32.WinDef.DWORD) UINT_PTR(com.sun.jna.platform.win32.WinDef.UINT_PTR) APPBARDATA(com.sun.jna.platform.win32.ShellAPI.APPBARDATA) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 34 with DWORD

use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.

the class Shell32Test method testResizeDesktopFromTop.

public void testResizeDesktopFromTop() throws InterruptedException {
    newAppBar();
    APPBARDATA data = new APPBARDATA.ByReference();
    data.uEdge.setValue(ShellAPI.ABE_TOP);
    data.rc.top = 0;
    data.rc.left = 0;
    data.rc.bottom = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN) - RESIZE_DELTA;
    data.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN);
    queryPos(data);
    UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETPOS), data);
    assertNotNull(h);
    assertTrue(h.intValue() >= 0);
    removeAppBar();
}
Also used : DWORD(com.sun.jna.platform.win32.WinDef.DWORD) UINT_PTR(com.sun.jna.platform.win32.WinDef.UINT_PTR) APPBARDATA(com.sun.jna.platform.win32.ShellAPI.APPBARDATA) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 35 with DWORD

use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.

the class User32Test method testAdjustWindowRect.

@Test
public final void testAdjustWindowRect() {
    RECT lpRect = new RECT();
    lpRect.left = 100;
    lpRect.top = 200;
    lpRect.bottom = 300;
    lpRect.right = 500;
    assertTrue(User32.INSTANCE.AdjustWindowRect(lpRect, new DWORD(WinUser.WS_THICKFRAME), new BOOL(1)).booleanValue());
    assertTrue(lpRect.left < 100);
    assertTrue(lpRect.top < 200);
    assertTrue(lpRect.bottom > 300);
    assertTrue(lpRect.right > 500);
}
Also used : RECT(com.sun.jna.platform.win32.WinDef.RECT) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) Test(org.junit.Test)

Aggregations

DWORD (com.sun.jna.platform.win32.WinDef.DWORD)56 PointerByReference (com.sun.jna.ptr.PointerByReference)23 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)17 File (java.io.File)17 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)16 Test (org.junit.Test)15 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)11 Memory (com.sun.jna.Memory)9 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)9 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)7 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 UINT_PTR (com.sun.jna.platform.win32.WinDef.UINT_PTR)5 TOKEN_PRIVILEGES (com.sun.jna.platform.win32.WinNT.TOKEN_PRIVILEGES)5 IntByReference (com.sun.jna.ptr.IntByReference)5 APPBARDATA (com.sun.jna.platform.win32.ShellAPI.APPBARDATA)4 WinNT (com.sun.jna.platform.win32.WinNT)4 Pointer (com.sun.jna.Pointer)3 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)3 BufferedWriter (java.io.BufferedWriter)3