Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert void** pointer to equivalent Java type

I'm loading a C DLL from a program written in Java. I want to be able to call one of the methods from the DLL with this declaration :

dll_function(const char* foo1, const char* foo2, const char* foo3, void** bar, size_t* bar2);

How do I call this method with arguments of correct type in Java ? I know (theorically) how to call it, but what I would like to know is how to pass the "void**" and "size_t*" from my Java program ? Basically, I want to know what the "equivalent type" for void and size_t*** is in Java...

I found the Pointer class but didn't manage to get it work ? Many thanks :)

like image 413
Guillaume Voiron Avatar asked Apr 15 '13 14:04

Guillaume Voiron


1 Answers

I worked on a Java/JNI/C project several years ago, and we had to maintain opaque C pointers within Java objects. We used long values on the Java side to hold the C pointers, which were converted on the JNI side from jlong to void* or whatever pointer type we needed.

Since the Java long type is 64 bits wide, and JNI/C pointers are typically either 32 bits or 64 bits wide, we did not have any problems converting between them.

like image 74
David R Tribble Avatar answered Sep 20 '22 18:09

David R Tribble