Define/Instantiate a java object from c/c++

牧云@^-^@ 提交于 2019-12-05 21:29:11

I managed to solve the problem by defining the Listener class in java. The listener has a native method with the desired callback signature.

public class MyImpl implements MyInterface
{
  @override
  public native int callback(int i);
}

Compiled this using javac. Then using javah to produce the function declaration to be used with JNI. In the C program I defined the function and loaded Impl class and registered callback into it using RegisterNatives.

P.S. The question of how to actually define a class using JNI remains unanswered.

EDIT:
There's a downside to using this method. I will have to register callbacks in class scope not object scope.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!