在JNA中将回调变成指针

编程入门 行业动态 更新时间:2024-10-19 01:18:46
本文介绍了在JNA中将回调变成指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一定很想念东西.给定实现com.sun.jna.Callback的类的实例,如何获取函数指针地址作为Pointer,以便可以将其传递给带有void*参数的函数(我正在使用Pointer ).

I must be missing something. Given an instance of a class that implements com.sun.jna.Callback, how do I get a function pointer address as a Pointer, so that I can pass it to a function that takes a void* parameter (I’m using Pointer).

具体来说,我想使用CFNumber(又名NSNumber*) .html#//apple_ref/c/func/CFNumberCreate"rel =" nofollow> CFNumberCreate(Pointer, int, Pointer) ,带有函数的地址,这样我就可以调用 SetSpeechProperty 来注册 SpeechDoneProcPtr .

Specifically, I want to create a CFNumber (aka NSNumber*) using CFNumberCreate(Pointer, int, Pointer) with the address of the function, so that I can call SetSpeechProperty to register a SpeechDoneProcPtr.

推荐答案

您没有.您传递回调实例,并让JNA处理指针转换.确保对回调对象保持强烈的引用,这样它就不会被垃圾回收.

You don't. You pass the callback instance and let JNA handle the pointer conversions. Make sure you keep a strong reference to the callback object so it doesn't get GC'd.

如果需要,进行另一个使用您的回调类型而不是Pointer的函数映射.

If you need to, make another function mapping that uses your callback type instead of Pointer.

您可以获得回调实例的本地指针值,但是几乎没有理由需要这样做.

You can get the native pointer value for a callback instance, but there are very few reasons why you'd ever need to.

更多推荐

在JNA中将回调变成指针

本文发布于:2023-11-25 15:22:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   中将   回调   JNA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!