7

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 :)

4

3 に答える 3

2

私は数年前に Java/JNI/C プロジェクトに取り組みましたが、Java オブジェクト内で不透明な C ポインターを維持する必要がありました。longJava 側で値を使用して C ポインターを保持しました。これは、JNI 側jlongvoid*必要なポインター型に変換されました。

Javalong型は 64 ビット幅であり、JNI/C ポインターは通常 32 ビット幅または 64 ビット幅であるため、それらの間の変換に問題はありませんでした。

于 2013-04-15T20:40:34.063 に答える
0

私はあなたの解決策を試しましたが、私は本当に正しく理解していなかったと思います... しかし、私はこれを使用して問題を解決しました:

import com.sun.jna.ptr.IntByReference;

私は Java Program でそのような C 関数を呼び出しました:

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

C 関数 "myCFunction" は次のようになります。

void myCFunction(void** parameter);

それをしてもいいですか?それは機能していますが、それが正しい方法であるかどうか疑問に思っていました。

于 2013-04-16T12:01:59.303 に答える