最近在调取第三方c++SDK的时候遇到的问题,
接口文档表示传给他一个hWnd就能渲染视频,
但是我使用的是javafx,如果是swing的话JNA的 Native.getComponentID可以直接获取awt.Component的句柄去渲染。所以找啊找啊找终于在谷歌找到了解决办法(百度真垃圾

 private static Long getWindowPointer(Stage stage) {
        try {
            Method tkStageGetter;
            try {
                // java 9
                tkStageGetter = stage.getClass().getSuperclass().getDeclaredMethod("getPeer");
            } catch (NoSuchMethodException ex) {
                // java 8
                tkStageGetter = stage.getClass().getMethod("impl_getPeer");
            }
            tkStageGetter.setAccessible(true);
            TKStage tkStage = (TKStage) tkStageGetter.invoke(stage);
            Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow");
            getPlatformWindow.setAccessible(true);
            Object platformWindow = getPlatformWindow.invoke(tkStage);
            Method getNativeHandle = platformWindow.getClass().getMethod("getNativeHandle");
            getNativeHandle.setAccessible(true);
            Object nativeHandle = getNativeHandle.invoke(platformWindow);
            return (long) nativeHandle;
        } catch (Throwable e) {
            System.err.println("Error getting Window Pointer");
            e.printStackTrace();
            return null;
        }
    }

如果是javafx version > 8 需要在启动项中添加:

--add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
--add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
--add-opens javafx.graphics/javafx.stage=ALL-UNNAMED
--add-opens javafx.graphics/com.sun.javafx.tk.quantum=ALL-UNNAMED

答案地址:https://github.com/java-native-access/jna/issues/706