Reputation: 1133
Let us consider that we need to pass a structured form of callbacks to native code dll. One of the callbacks has the following form in C notation:
int myfunc (int arg1,int* arg2,int arg3,int arg4);//it is marked as stdcall in real app
Here arg2 is an array of ints. arg1 determines the number of elements in arg2.
Here is Java code:
public class TRCallbackCollection extends Structure{
public int fieldsCount;
public StdCallLibrary.StdCallCallback myfunc;
//...
}
//...
TRCallbackCollection callbacks= new TRCallbackCollection();
callbacks.fieldsCount = 7;
callbacks.myfunc = new StdCallLibrary.StdCallCallback(){
public int callback (int arg1, int[] arg2,int arg3,int arg4) {
return 0;
}
};
I've got the followin error:
java.lang.IllegalArgumentException: Structure field "myfunc" was declared as interface com.sun.jna.win32.StdCallLibrary$StdCallCallback, which is not supported within a Structure,
when I try to init native dll with the instance of TRCallbackCollection structure:
lib.InitKernel(callbacks,5);
Other callbacks work fine. I think that the problem is linked with int[] arg2
in method. How should I transform it and use as the array within callback?
Upvotes: 2
Views: 1508
Reputation: 1133
Success; other StdCallCallback fields worked!
Fortunately, I've solved the problem. I used Pointer arg2
instead of int[] arg2
.
Upvotes: 4