Search in sources :

Example 71 with Pointer

use of com.sun.jna.Pointer in project jmonkeyengine by jMonkeyEngine.

the class OSVRInput method init.

@Override
public boolean init() {
    logger.config("Initialize OSVR input.");
    buttonHandler = new Callback() {

        @SuppressWarnings("unused")
        public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < BUTTON_COUNT; j++) {
                    if (buttons[i][j] == null)
                        continue;
                    if (userdata.toString().equals(buttons[i][j].getPointer().toString())) {
                        buttonState[i][j] = report.state;
                        return;
                    }
                }
            }
        }
    };
    analogHandler = new Callback() {

        @SuppressWarnings("unused")
        public void invoke(Pointer userdata, Pointer timeval, OSVR_AnalogReport report) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < ANALOG_COUNT; j++) {
                    for (int k = 0; k < CHANNEL_COUNT; k++) {
                        if (analogs[i][j][k] == null)
                            continue;
                        if (userdata.toString().equals(analogs[i][j][k].getPointer().toString())) {
                            analogState[i][j][k] = (float) report.state;
                            return;
                        }
                    }
                }
            }
        }
    };
    buttons = new OSVR_ClientInterface[2][BUTTON_COUNT];
    analogs = new OSVR_ClientInterface[2][ANALOG_COUNT][CHANNEL_COUNT];
    buttonState = new float[2][BUTTON_COUNT];
    analogState = new float[2][ANALOG_COUNT][CHANNEL_COUNT];
    hands = new OSVR_ClientInterface[2];
    hands[0] = getInterface(leftHand);
    hands[1] = getInterface(rightHand);
    handState = new OSVR_Pose3[2];
    handState[0] = new OSVR_Pose3();
    handState[1] = new OSVR_Pose3();
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < BUTTON_COUNT - 2; i++) {
            buttons[h][i] = getInterface(getButtonString(h == 0, (byte) Integer.toString(i).toCharArray()[0]));
            OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[h][i], buttonHandler, buttons[h][i].getPointer());
        }
    }
    buttons[0][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 2], buttonHandler, buttons[0][BUTTON_COUNT - 2].getPointer());
    buttons[1][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 2], buttonHandler, buttons[1][BUTTON_COUNT - 2].getPointer());
    buttons[0][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 1], buttonHandler, buttons[0][BUTTON_COUNT - 1].getPointer());
    buttons[1][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 1], buttonHandler, buttons[1][BUTTON_COUNT - 1].getPointer());
    analogs[0][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
    analogs[1][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][0][0], analogHandler, analogs[0][0][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][0][0], analogHandler, analogs[1][0][0].getPointer());
    analogs[0][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
    analogs[0][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][0], analogHandler, analogs[0][1][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][1], analogHandler, analogs[0][1][1].getPointer());
    analogs[1][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
    analogs[1][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][0], analogHandler, analogs[1][1][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][1], analogHandler, analogs[1][1][1].getPointer());
    return true;
}
Also used : Callback(com.sun.jna.Callback) OSVR_ButtonReport(com.jme3.system.osvr.osvrclientreporttypes.OSVR_ButtonReport) OSVR_Pose3(com.jme3.system.osvr.osvrclientreporttypes.OSVR_Pose3) Pointer(com.sun.jna.Pointer) OSVR_AnalogReport(com.jme3.system.osvr.osvrclientreporttypes.OSVR_AnalogReport)

Example 72 with Pointer

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

the class AlphaMaskDemo method updateW32.

private void updateW32(boolean a, boolean i) {
    User32 user = User32.INSTANCE;
    GDI32 gdi = GDI32.INSTANCE;
    HWND hWnd = null;
    if (!alphaWindow.isDisplayable()) {
        alphaWindow.pack();
        hWnd = getHwnd(alphaWindow);
        int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
        flags |= WinUser.WS_EX_LAYERED;
        user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
        Window parent = alphaWindow.getOwner();
        Point where = parent.getLocationOnScreen();
        where.translate(parent.getWidth(), 0);
        alphaWindow.setLocation(where);
    } else {
        hWnd = getHwnd(alphaWindow);
    }
    if (i) {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        HDC screenDC = user.GetDC(null);
        HDC memDC = gdi.CreateCompatibleDC(screenDC);
        HBITMAP hBitmap = null;
        HANDLE oldBitmap = null;
        try {
            BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics g = buf.getGraphics();
            g.drawImage(image, 0, 0, w, h, null);
            BITMAPINFO bmi = new BITMAPINFO();
            bmi.bmiHeader.biWidth = w;
            bmi.bmiHeader.biHeight = h;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 32;
            bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
            bmi.bmiHeader.biSizeImage = w * h * 4;
            PointerByReference ppbits = new PointerByReference();
            hBitmap = gdi.CreateDIBSection(memDC, bmi, WinGDI.DIB_RGB_COLORS, ppbits, null, 0);
            oldBitmap = gdi.SelectObject(memDC, hBitmap);
            Pointer pbits = ppbits.getValue();
            Raster raster = buf.getData();
            int[] pixel = new int[4];
            int[] bits = new int[w * h];
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    raster.getPixel(x, h - y - 1, pixel);
                    int alpha = (pixel[3] & 0xFF) << 24;
                    int red = (pixel[2] & 0xFF);
                    int green = (pixel[1] & 0xFF) << 8;
                    int blue = (pixel[0] & 0xFF) << 16;
                    bits[x + y * w] = alpha | red | green | blue;
                }
            }
            pbits.write(0, bits, 0, bits.length);
            SIZE size = new SIZE();
            size.cx = w;
            size.cy = h;
            POINT loc = new POINT();
            loc.x = alphaWindow.getX();
            loc.y = alphaWindow.getY();
            POINT srcLoc = new POINT();
            BLENDFUNCTION blend = new BLENDFUNCTION();
            blend.SourceConstantAlpha = (byte) (alpha * 255);
            blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
            user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc, 0, blend, WinUser.ULW_ALPHA);
        } finally {
            user.ReleaseDC(null, screenDC);
            if (hBitmap != null) {
                gdi.SelectObject(memDC, oldBitmap);
                gdi.DeleteObject(hBitmap);
            }
            gdi.DeleteDC(memDC);
        }
    } else if (a) {
        BLENDFUNCTION blend = new BLENDFUNCTION();
        blend.SourceConstantAlpha = (byte) (alpha * 255);
        blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
        user.UpdateLayeredWindow(hWnd, null, null, null, null, null, 0, blend, WinUser.ULW_ALPHA);
    }
    if (!alphaWindow.isVisible()) {
        alphaWindow.setVisible(true);
    }
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) GDI32(com.sun.jna.platform.win32.GDI32) BLENDFUNCTION(com.sun.jna.platform.win32.WinUser.BLENDFUNCTION) HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) Raster(java.awt.image.Raster) SIZE(com.sun.jna.platform.win32.WinUser.SIZE) Pointer(com.sun.jna.Pointer) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) BITMAPINFO(com.sun.jna.platform.win32.WinGDI.BITMAPINFO) PointerByReference(com.sun.jna.ptr.PointerByReference) User32(com.sun.jna.platform.win32.User32) HBITMAP(com.sun.jna.platform.win32.WinDef.HBITMAP) POINT(com.sun.jna.platform.win32.WinDef.POINT) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 73 with Pointer

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

the class Advapi32Util method getSecurityDescriptorForObject.

/**
     * Get a self relative security descriptor for the given object type. The value is returned in Memory
     * @param absoluteObjectPath
     *         A pointer to a null-terminated string that specifies the name of the object
     *         from which to retrieve security information. For descriptions of the string
     *         formats for the different object types, see SE_OBJECT_TYPE in
     *         {@link AccCtrl.SE_OBJECT_TYPE}
     * @param objectType
     *         Object type referred to by the path. See  {@link AccCtrl.SE_OBJECT_TYPE} for valid definitions.
     * @param getSACL
     *         Get SACL of the object. See {@link Advapi32#GetNamedSecurityInfo} for process privilege requirements in getting the SACL.
     * @return Memory containing the self relative security descriptor
     */
public static Memory getSecurityDescriptorForObject(final String absoluteObjectPath, int objectType, boolean getSACL) {
    int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | (getSACL ? SACL_SECURITY_INFORMATION : 0);
    PointerByReference ppSecurityDescriptor = new PointerByReference();
    int lastError = Advapi32.INSTANCE.GetNamedSecurityInfo(absoluteObjectPath, objectType, infoType, null, null, null, null, ppSecurityDescriptor);
    if (lastError != 0) {
        throw new Win32Exception(lastError);
    }
    int nLength = Advapi32.INSTANCE.GetSecurityDescriptorLength(ppSecurityDescriptor.getValue());
    Memory memory = new Memory(nLength);
    Pointer secValue = ppSecurityDescriptor.getValue();
    try {
        byte[] data = secValue.getByteArray(0, nLength);
        memory.write(0, data, 0, nLength);
        return memory;
    } finally {
        Kernel32Util.freeLocalMemory(secValue);
    }
}
Also used : Memory(com.sun.jna.Memory) PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer)

Example 74 with Pointer

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

the class Advapi32Util method convertSidToStringSid.

/**
	 * Convert a security identifier (SID) to a string format suitable for
	 * display, storage, or transmission.
	 *
	 * @param sid
	 *            SID bytes.
	 * @return String SID.
	 */
public static String convertSidToStringSid(PSID sid) {
    PointerByReference stringSid = new PointerByReference();
    if (!Advapi32.INSTANCE.ConvertSidToStringSid(sid, stringSid)) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    Pointer ptr = stringSid.getValue();
    try {
        return ptr.getWideString(0);
    } finally {
        Kernel32Util.freeLocalMemory(ptr);
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer)

Example 75 with Pointer

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

the class VersionUtil method getFileVersionInfo.

/**
     * Gets the file's version number info
     * 
     * @param filePath
     *            The path to the file
     * @return The VS_FIXEDFILEINFO structure read from the file.<br>
     *         Use the getFileVersionMajor(), getFileVersionMinor(),
     *         getFileVersionRevision(), and getFileVersionBuild()
     * @throws UnsupportedOperationException
     *             if VerQueryValue fails to get version info from the file.
     */
public static VS_FIXEDFILEINFO getFileVersionInfo(String filePath) {
    IntByReference dwDummy = new IntByReference();
    int versionLength = Version.INSTANCE.GetFileVersionInfoSize(filePath, dwDummy);
    // throw a Win32Exception with GetLastError()
    if (versionLength == 0) {
        throw new Win32Exception(Native.getLastError());
    }
    // buffer to hold version info
    Pointer lpData = new Memory(versionLength);
    // pointer to pointer to location in aforementioned buffer
    PointerByReference lplpBuffer = new PointerByReference();
    if (!Version.INSTANCE.GetFileVersionInfo(filePath, 0, versionLength, lpData)) {
        throw new Win32Exception(Native.getLastError());
    }
    // here to make VerQueryValue happy.
    IntByReference puLen = new IntByReference();
    // this does not set GetLastError, so no need to throw a Win32Exception
    if (!Version.INSTANCE.VerQueryValue(lpData, "\\", lplpBuffer, puLen)) {
        throw new UnsupportedOperationException("Unable to extract version info from the file: \"" + filePath + "\"");
    }
    VS_FIXEDFILEINFO fileInfo = new VS_FIXEDFILEINFO(lplpBuffer.getValue());
    fileInfo.read();
    return fileInfo;
}
Also used : VS_FIXEDFILEINFO(com.sun.jna.platform.win32.VerRsrc.VS_FIXEDFILEINFO) IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Aggregations

Pointer (com.sun.jna.Pointer)93 PointerByReference (com.sun.jna.ptr.PointerByReference)20 Memory (com.sun.jna.Memory)15 IntByReference (com.sun.jna.ptr.IntByReference)15 Test (org.junit.Test)12 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)8 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)8 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)7 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)7 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)7 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 File (java.io.File)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 HWND (com.sun.jna.platform.win32.WinDef.HWND)6 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)6 IOException (java.io.IOException)6 BufferedImage (java.awt.image.BufferedImage)5 Function (com.sun.jna.Function)4 ULONG_PTR (com.sun.jna.platform.win32.BaseTSD.ULONG_PTR)4