Convert void ** pointer to Java equivalent type

I am loading the 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 the correct type in Java? I know (theoretically) what to call it, but what I would like to know is to pass "void **" and "size_t *" from my Java program? Basically, I want to know what the "equivalent type" means for void and size_t *** in Java ...

I found a Pointer class but couldn't get it to work? Thank you very much:)

+6
source share
3 answers

size_t is the integer used to size the variable in memory; as such, you should be safe with unsigned long in Java.

void* most likely a pointer to an object of an unknown type. This question is very interesting on this issue. The Java Object usually used in this case, but I don’t know how you convert between them, although this question may help there.

+1
source

A few years ago, I was working on a Java / JNI / C project, and we had to maintain opaque C pointers inside Java objects. We used long values ​​on the Java side to store C pointers that were converted on the JNI side from jlong to void* or any other type of pointer we need.

Since the Java long type has a width of 64 bits, and JNI / C pointers usually have a width of 32 or 64 bits, we had no problems converting between them.

+1
source

I tried your solutions, but I think I really did not understand correctly ... But I solved my problem using this:

 import com.sun.jna.ptr.IntByReference; 

I called the C function as in my Java program:

 IntByReference myVoidPointerPointer = new IntByReference(); myCLibrary.myCFunction(myVoidPointerPointer); 

The C function "myCFunction" looks like this:

 void myCFunction(void** parameter); 

Can this be done? This works, but I was wondering if this is the right thing to do.

0
source

All Articles