繁体   English   中英

Java Native Access具有浮点指针的回调函数

[英]Java Native Access a callback function with a float pointer

我有一个公开以下功能的C ++ DLL。 此函数立即调用回调函数( GetProperty )。 我无法更改C ++ DLL

// c++
DllExport unsigned int RegisterCallbackGetPropertyReal( bool (*GetProperty)( UINT property_identifer, float * value ) ) ; 

我有一个使用com.sun.jna来访问DLL的此功能的C#应用​​程序。 我已经到了从C ++ DLL正确调用回调函数的地步,但是我看不出找到设置float * value

// Java 
public class main {
    public interface CBlargAPI extends Library {
        interface GetPropertyReal_t extends Callback {
            boolean invoke (int property_identifer, FloatByReference value);
        }
        int RegisterCallbackGetPropertyReal( GetPropertyReal_t getProperty ) ; 
    }

    public static void main(String[] args) throws Exception 
    {
        // Register call back functions         
        CBlargAPI.GetPropertyReal_t GetPropertyReal_fn = new CBACnetAPI.GetPropertyReal_t() {
            @Override
            public boolean invoke(int property_identifer, FloatByReference value) {
                System.out.println("GetPropertyReal_t: " )  ;
                value.setValue(97.5f); 
                return false; // [Edit] This is where the problem was. this should be `return true;` See my answer below. 
            }
        };
        CBlargAPI.INSTANCE.RegisterCallbackGetPropertyReal( GetPropertyReal_fn ) ;             
    }
}

我期望的是,当它返回到C ++ DLL时,该值应设置为97.5f。 相反,我得到的默认值为0.000f

我的问题是:

  • 如何使用Jna在Java中正确设置浮点指针值?

这是其他人找不到的错字。 基本上,如果我在GetPropertyReal_fn回调上返回false,则将使用默认值0.000f

我已经编辑了问题以显示错误在哪里。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM