我一定很想念东西.给定实现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中将回调变成指针
发布评论