Search in sources :

Example 16 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 17 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)

Example 18 with DWORDByReference

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

the class Dxva2Test method setUp.

@Before
public void setUp() {
    HMONITOR hMonitor = User32.INSTANCE.MonitorFromWindow(User32.INSTANCE.GetDesktopWindow(), WinUser.MONITOR_DEFAULTTOPRIMARY);
    DWORDByReference pdwNumberOfPhysicalMonitors = new DWORDByReference();
    assertTrue(Dxva2.INSTANCE.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, pdwNumberOfPhysicalMonitors).booleanValue());
    monitorCount = pdwNumberOfPhysicalMonitors.getValue().intValue();
    physMons = new PHYSICAL_MONITOR[monitorCount];
    assumeTrue(Dxva2.INSTANCE.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCount, physMons).booleanValue());
}
Also used : HMONITOR(com.sun.jna.platform.win32.WinUser.HMONITOR) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference)

Example 19 with DWORDByReference

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

the class Kernel32DiskManagementFunctionsTest method testGetDiskFreeSpace.

private void testGetDiskFreeSpace(String lpRootPathName) {
    DWORDByReference lpSectorsPerCluster = new DWORDByReference();
    DWORDByReference lpBytesPerSector = new DWORDByReference();
    DWORDByReference lpNumberOfFreeClusters = new DWORDByReference();
    DWORDByReference lpTotalNumberOfClusters = new DWORDByReference();
    assertCallSucceeded("GetDiskFreeSpace(" + lpRootPathName + ")", Kernel32.INSTANCE.GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters));
    //        System.out.append(getCurrentTestName()).append('[').append(lpRootPathName).println(']');
    //        System.out.append('\t').append("SectorsPerCluster: ").println(lpSectorsPerCluster.getValue());
    //        System.out.append('\t').append("BytesPerSector: ").println(lpBytesPerSector.getValue());
    //        System.out.append('\t').append("NumberOfFreeClusters: ").println(lpNumberOfFreeClusters.getValue());
    //        System.out.append('\t').append("TotalNumberOfClusters: ").println(lpTotalNumberOfClusters.getValue());
    DWORD freeSize = lpNumberOfFreeClusters.getValue();
    assertTrue("No free clusters for " + lpRootPathName, freeSize.longValue() > 0L);
    DWORD totalSize = lpTotalNumberOfClusters.getValue();
    assertTrue("Free clusters (" + freeSize + ") not below total (" + totalSize + ") for " + lpRootPathName, freeSize.longValue() < totalSize.longValue());
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 20 with DWORDByReference

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

the class Dxva2Test method testGetMonitorContrast.

@Test
public void testGetMonitorContrast() {
    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 pdwMinimumContrast = new DWORDByReference();
    DWORDByReference pdwCurrentContrast = new DWORDByReference();
    DWORDByReference pdwMaximumContrast = new DWORDByReference();
    Dxva2.INSTANCE.GetMonitorContrast(hPhysicalMonitor, pdwMinimumContrast, pdwCurrentContrast, pdwMaximumContrast);
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

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