Search in sources :

Example 36 with IntByReference

use of com.sun.jna.ptr.IntByReference 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)

Example 37 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class PsapiTest method testGetModuleFileNameEx.

@Test
public void testGetModuleFileNameEx() {
    final JFrame w = new JFrame();
    try {
        w.setVisible(true);
        final String searchSubStr = "\\bin\\java";
        final HWND hwnd = new HWND(Native.getComponentPointer(w));
        final IntByReference pid = new IntByReference();
        User32.INSTANCE.GetWindowThreadProcessId(hwnd, pid);
        final HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010, false, pid.getValue());
        if (process == null)
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        // check ANSI function
        final byte[] filePathAnsi = new byte[1025];
        int length = Psapi.INSTANCE.GetModuleFileNameExA(process, null, filePathAnsi, filePathAnsi.length - 1);
        if (length == 0)
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathAnsi), Native.toString(filePathAnsi).toLowerCase().contains(searchSubStr));
        // check Unicode function
        final char[] filePathUnicode = new char[1025];
        length = Psapi.INSTANCE.GetModuleFileNameExW(process, null, filePathUnicode, filePathUnicode.length - 1);
        if (length == 0)
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathUnicode), Native.toString(filePathUnicode).toLowerCase().contains(searchSubStr));
        // check default function
        final int memAllocSize = 1025 * Native.WCHAR_SIZE;
        final Memory filePathDefault = new Memory(memAllocSize);
        length = Psapi.INSTANCE.GetModuleFileNameEx(process, null, filePathDefault, (memAllocSize / Native.WCHAR_SIZE) - 1);
        if (length == 0)
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathDefault.getCharArray(0, memAllocSize / Native.WCHAR_SIZE)), Native.toString(filePathDefault.getCharArray(0, memAllocSize / Native.WCHAR_SIZE)).toLowerCase().contains(searchSubStr));
    } finally {
        w.dispose();
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) JFrame(javax.swing.JFrame) Memory(com.sun.jna.Memory) HWND(com.sun.jna.platform.win32.WinDef.HWND) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) Test(org.junit.Test)

Example 38 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class Rasapi32Test method testRasGetEntryProperties.

public void testRasGetEntryProperties() {
    RASENTRY.ByReference rasEntry = new RASENTRY.ByReference();
    IntByReference lpdwEntryInfoSize = new IntByReference(rasEntry.size());
    int err = Rasapi32.INSTANCE.RasGetEntryProperties(null, "TEST", rasEntry, lpdwEntryInfoSize, null, null);
    assertEquals(623, err);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) RASENTRY(com.sun.jna.platform.win32.WinRas.RASENTRY) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) IntByReference(com.sun.jna.ptr.IntByReference)

Example 39 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jmonkeyengine by jMonkeyEngine.

the class OpenVR method initVRCompositor.

@Override
public boolean initVRCompositor(boolean allowed) {
    // clear the error store
    hmdErrorStore.setValue(0);
    if (allowed && vrsystemFunctions != null) {
        IntByReference intptr = JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRCompositor_Version, hmdErrorStore);
        if (intptr != null) {
            if (intptr.getPointer() != null) {
                compositorFunctions = new VR_IVRCompositor_FnTable(intptr.getPointer());
                if (compositorFunctions != null && hmdErrorStore.getValue() == 0) {
                    compositorFunctions.setAutoSynch(false);
                    compositorFunctions.read();
                    if (environment.isSeatedExperience()) {
                        compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated);
                    } else {
                        compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding);
                    }
                    logger.config("OpenVR Compositor initialized");
                } else {
                    logger.severe("OpenVR Compositor error: " + hmdErrorStore.getValue());
                    compositorFunctions = null;
                }
            } else {
                logger.log(Level.SEVERE, "Cannot get valid pointer for generic interface \"" + JOpenVRLibrary.IVRCompositor_Version + "\", " + OpenVRUtil.getEVRInitErrorString(hmdErrorStore.getValue()) + " (" + hmdErrorStore.getValue() + ")");
                compositorFunctions = null;
            }
        } else {
            logger.log(Level.SEVERE, "Cannot get generic interface for \"" + JOpenVRLibrary.IVRCompositor_Version + "\", " + OpenVRUtil.getEVRInitErrorString(hmdErrorStore.getValue()) + " (" + hmdErrorStore.getValue() + ")");
            compositorFunctions = null;
        }
    }
    if (compositorFunctions == null) {
        logger.severe("Skipping VR Compositor...");
        if (vrsystemFunctions != null) {
            vsyncToPhotons = vrsystemFunctions.GetFloatTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd, JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_SecondsFromVsyncToPhotons_Float, hmdErrorStore);
        } else {
            vsyncToPhotons = 0f;
        }
    }
    return compositorFunctions != null;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) VR_IVRCompositor_FnTable(com.jme3.system.jopenvr.VR_IVRCompositor_FnTable)

Example 40 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jmonkeyengine by jMonkeyEngine.

the class OpenVR method initialize.

@Override
public boolean initialize() {
    logger.config("Initializing OpenVR system...");
    hmdErrorStore = new IntByReference();
    vrsystemFunctions = null;
    JOpenVRLibrary.VR_InitInternal(hmdErrorStore, JOpenVRLibrary.EVRApplicationType.EVRApplicationType_VRApplication_Scene);
    if (hmdErrorStore.getValue() == 0) {
        vrsystemFunctions = new VR_IVRSystem_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRSystem_Version, hmdErrorStore).getPointer());
    }
    if (vrsystemFunctions == null || hmdErrorStore.getValue() != 0) {
        logger.severe("OpenVR Initialize Result: " + JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.getValue()).getString(0));
        logger.severe("Initializing OpenVR system [FAILED]");
        return false;
    } else {
        logger.config("OpenVR initialized & VR connected.");
        vrsystemFunctions.setAutoSynch(false);
        vrsystemFunctions.read();
        tlastVsync = new FloatByReference();
        _tframeCount = new LongByReference();
        hmdDisplayFrequency = IntBuffer.allocate(1);
        hmdDisplayFrequency.put((int) JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_DisplayFrequency_Float);
        hmdTrackedDevicePoseReference = new TrackedDevicePose_t.ByReference();
        hmdTrackedDevicePoses = (TrackedDevicePose_t[]) hmdTrackedDevicePoseReference.toArray(JOpenVRLibrary.k_unMaxTrackedDeviceCount);
        poseMatrices = new Matrix4f[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
        for (int i = 0; i < poseMatrices.length; i++) poseMatrices[i] = new Matrix4f();
        timePerFrame = 1.0 / hmdDisplayFrequency.get(0);
        // disable all this stuff which kills performance
        hmdTrackedDevicePoseReference.setAutoRead(false);
        hmdTrackedDevicePoseReference.setAutoWrite(false);
        hmdTrackedDevicePoseReference.setAutoSynch(false);
        for (int i = 0; i < JOpenVRLibrary.k_unMaxTrackedDeviceCount; i++) {
            hmdTrackedDevicePoses[i].setAutoRead(false);
            hmdTrackedDevicePoses[i].setAutoWrite(false);
            hmdTrackedDevicePoses[i].setAutoSynch(false);
        }
        // init controllers for the first time
        VRinput = new OpenVRInput(environment);
        VRinput.init();
        VRinput.updateConnectedControllers();
        // init bounds & chaperone info
        VRBounds.init();
        logger.config("Initializing OpenVR system [SUCCESS]");
        initSuccess = true;
        return true;
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Matrix4f(com.jme3.math.Matrix4f) FloatByReference(com.sun.jna.ptr.FloatByReference) LongByReference(com.sun.jna.ptr.LongByReference) TrackedDevicePose_t(com.jme3.system.jopenvr.TrackedDevicePose_t) VR_IVRSystem_FnTable(com.jme3.system.jopenvr.VR_IVRSystem_FnTable)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)199 PointerByReference (com.sun.jna.ptr.PointerByReference)38 Memory (com.sun.jna.Memory)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)26 File (java.io.File)19 Pointer (com.sun.jna.Pointer)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 PSID (com.sun.jna.platform.win32.WinNT.PSID)13 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)11 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)11 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)8 Advapi32 (com.sun.jna.platform.win32.Advapi32)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)6 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)6 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)6 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)5