Search in sources :

Example 31 with DWORDByReference

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

the class Dxva2Test method testCapabilitiesRequestAndCapabilitiesReply.

@Test
public void testCapabilitiesRequestAndCapabilitiesReply() {
    HANDLE hPhysicalMonitor = physMons[0].hPhysicalMonitor;
    // the method returns FALSE if the monitor driver doesn't support it,
    // but verifies that the JNA mapping is correct (no exception)
    DWORDByReference pdwCapabilitiesStringLengthInCharacters = new DWORDByReference();
    BOOL success = Dxva2.INSTANCE.GetCapabilitiesStringLength(hPhysicalMonitor, pdwCapabilitiesStringLengthInCharacters);
    if (success.booleanValue()) {
        // VirtualBox is known to report an empty string
        DWORD capStrLen = pdwCapabilitiesStringLengthInCharacters.getValue();
        LPSTR pszASCIICapabilitiesString = new LPSTR(new Memory(capStrLen.intValue()));
        Dxva2.INSTANCE.CapabilitiesRequestAndCapabilitiesReply(hPhysicalMonitor, pszASCIICapabilitiesString, capStrLen);
    } else {
        System.err.println("GetCapabilitiesStringLength failed with errorcode: " + Kernel32.INSTANCE.GetLastError());
    }
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) Memory(com.sun.jna.Memory) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) LPSTR(com.sun.jna.platform.win32.WTypes.LPSTR) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 32 with DWORDByReference

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

the class WindowUtilsTest method testGetIconSize.

public void testGetIconSize() throws Exception {
    final JFrame w = new JFrame();
    try {
        final BufferedImage expectedIcon = ImageIO.read(new FileInputStream(new File(getClass().getResource("/res/test_icon.png").getPath())));
        w.setIconImage(expectedIcon);
        w.setVisible(true);
        Pointer p = Native.getComponentPointer(w);
        assertNotNull("Could not obtain native HANDLE for JFrame", p);
        HWND hwnd = new HWND(p);
        final DWORDByReference hIconNumber = new DWORDByReference();
        LRESULT result = User32.INSTANCE.SendMessageTimeout(hwnd, WinUser.WM_GETICON, new WPARAM(WinUser.ICON_BIG), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
        assertNotEquals(0, result.intValue());
        final HICON hIcon = new HICON(new Pointer(hIconNumber.getValue().longValue()));
        assertTrue(WindowUtils.getIconSize(hIcon).width >= 32);
        assertTrue(WindowUtils.getIconSize(hIcon).height >= 32);
        assertEquals(WindowUtils.getIconSize(hIcon).width, WindowUtils.getIconSize(hIcon).height);
    } finally {
        w.dispose();
    }
}
Also used : LRESULT(com.sun.jna.platform.win32.WinDef.LRESULT) JFrame(javax.swing.JFrame) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) HWND(com.sun.jna.platform.win32.WinDef.HWND) LPARAM(com.sun.jna.platform.win32.WinDef.LPARAM) HICON(com.sun.jna.platform.win32.WinDef.HICON) Pointer(com.sun.jna.Pointer) File(java.io.File) WPARAM(com.sun.jna.platform.win32.WinDef.WPARAM) BufferedImage(java.awt.image.BufferedImage) FileInputStream(java.io.FileInputStream)

Example 33 with DWORDByReference

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

the class PdhTest method testQueryMultipleCounters.

@Test
public void testQueryMultipleCounters() {
    Collection<String> names = new LinkedList<String>();
    PDH_COUNTER_PATH_ELEMENTS elems = new PDH_COUNTER_PATH_ELEMENTS();
    elems.szObjectName = "Processor";
    elems.szInstanceName = "_Total";
    for (String n : new String[] { "% Processor Time", "% Idle Time", "% User Time" }) {
        elems.szCounterName = n;
        String counterName = makeCounterPath(pdh, elems);
        names.add(counterName);
    }
    HANDLEByReference ref = new HANDLEByReference();
    assertErrorSuccess("PdhOpenQuery", pdh.PdhOpenQuery(null, null, ref), true);
    HANDLE hQuery = ref.getValue();
    try {
        Map<String, HANDLE> handlesMap = new HashMap<String, HANDLE>(names.size());
        try {
            for (String counterName : names) {
                ref.setValue(null);
                assertErrorSuccess("PdhAddCounter[" + counterName + "]", pdh.PdhAddEnglishCounter(hQuery, counterName, null, ref), true);
                HANDLE hCounter = ref.getValue();
                handlesMap.put(counterName, hCounter);
            }
            assertErrorSuccess("PdhCollectQueryData", pdh.PdhCollectQueryData(hQuery), true);
            for (Map.Entry<String, HANDLE> ch : handlesMap.entrySet()) {
                String counterName = ch.getKey();
                HANDLE hCounter = ch.getValue();
                PDH_RAW_COUNTER rawCounter = new PDH_RAW_COUNTER();
                DWORDByReference lpdwType = new DWORDByReference();
                assertErrorSuccess("PdhGetRawCounterValue[" + counterName + "]", pdh.PdhGetRawCounterValue(hCounter, lpdwType, rawCounter), true);
                assertEquals("Bad counter data status for " + counterName, PdhMsg.PDH_CSTATUS_VALID_DATA, rawCounter.CStatus);
                showRawCounterData(System.out, counterName, rawCounter);
            }
        } finally {
            names.clear();
            for (Map.Entry<String, HANDLE> ch : handlesMap.entrySet()) {
                String name = ch.getKey();
                HANDLE hCounter = ch.getValue();
                int status = pdh.PdhRemoveCounter(hCounter);
                if (status != WinError.ERROR_SUCCESS) {
                    names.add(name);
                }
            }
            if (names.size() > 0) {
                fail("Failed to remove counters: " + names);
            }
        }
    } finally {
        assertErrorSuccess("PdhCloseQuery", pdh.PdhCloseQuery(hQuery), true);
    }
}
Also used : PDH_COUNTER_PATH_ELEMENTS(com.sun.jna.platform.win32.Pdh.PDH_COUNTER_PATH_ELEMENTS) HashMap(java.util.HashMap) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) PDH_RAW_COUNTER(com.sun.jna.platform.win32.Pdh.PDH_RAW_COUNTER) LinkedList(java.util.LinkedList) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 34 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference 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 35 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference 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)

Aggregations

DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)34 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)11 Test (org.junit.Test)8 Memory (com.sun.jna.Memory)6 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)6 DdeCallback (com.sun.jna.platform.win32.Ddeml.DdeCallback)3 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)3 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)3 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)3 PVOID (com.sun.jna.platform.win32.WinDef.PVOID)3 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)3 Pointer (com.sun.jna.Pointer)2 IID (com.sun.jna.platform.win32.Guid.IID)2 REFIID (com.sun.jna.platform.win32.Guid.REFIID)2 MC_DRIVE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_DRIVE_TYPE)2 MC_GAIN_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_GAIN_TYPE)2 MC_POSITION_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_POSITION_TYPE)2 MC_SIZE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_SIZE_TYPE)2