开发者

JNI mapping structure in java

I have a dll which has a method for e.g void abc(meth* myMeth) and a structure

struct meth
{
  int a;
  char b[255]; 
} 开发者_StackOverflow社区

The above code code is written in c. I need to map this to Java through JNI, and I am stuck. How can I pass a reference to the method abc as a pointer from a Java method, and how can I set the values of a and b and then pass back to Java again? Need An Urgent Help....Thanks


I do not know if this is an option for you, but consider using some higher level framework for managing the low-level details of JNI for you. Two options:

  • JNAerator, see also "Structs" chapter in reference documentation.
  • SWIG, see also "Structures and unions" chapter in reference documentation.

Personally I have used JNAerator and found it really helpful.


There is no mapping between Java classes and C structs (not sure about how JNA handles this); you'll have to create a Java class with the same members as your C struct and write C functions to convert between them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜