some questions about JNI. lazarus / 43-Android ---------------------------------------------------------------------- ROCABDEL · 2012-06-19 21:38 hello everyone ! I am trying to change bass.pas by introducing support for jni, to facilitate the use of this library multiplatform, but I am blocking here: Code: [Select]public interface SYNCPROC { void SYNCPROC(int handle, int channel, int data, Object user); } public static native int BASS_ChannelSetSync(int handle, int type, long param, SYNCPROC proc, Object user);  What is the signature of BASS_ChannelSetSync ? and how i can call it ? i proceed like this : Code: [Select]javaMethod_Bass_BASS_ChannelSetSync:= javaEnvRef^^.GetStaticMethodID(javaEnvRef, javaClass_Bass, 'BASS_ChannelSetSync', '(IIJLL)I');// Error in the first 'L' i think //I am not yet arrived here, only to correct me lParams[0].i:= Myhandle;                   //handle lParams[1].i:= 0                                    //type lParams[2].j:= 0;                                   //param lParams[3].l:= @Sync_CallBack;     //proc lParams[4].l := Self;                             //user lRetInt := javaEnvRef^^.CallStaticIntMethodA(javaEnvRef, javaClass_Bass, javaMethod_Bass_BASS_ChannelSetSync, @lParams[0]); correct the code or links are welcome  thank you for your time ---------------------------------------------------------------------- felipemdc · 2012-06-20 05:33 You are using the L signature wrongly. You cannot use just L, you need to write L; For example: Ljava/lang/Object; For the other one something like: Lorg/jouvieje/bass/Bass/SYNCPROC; About the parameters, you are getting them wrong here: lParams[4].l := Self;                             //user You cannot use Self, because your Self is a Pascal object and the routine expects a Java Object. You can create a new Java object using JNI: http://wiki.freepascal.org/Android_Programming#Example_1:_Creatin g_a_Java_object_and_calling_a_Java_method Also here: lParams[3].l:= @Sync_CallBack;     //proc This is also wrong, you need to pass a Java object here, not a pointer to what is probably a procedure. But now is the nasty thing. You need an object of a class which implements that interface. So far I don't know how to do that in JNI or if it is possible. I asked a question about this in the android-ndk group, let's see if anyone answers. My solution to cases which require using interfaces so far has been creating a new routine in the .java file of the project which makes the necessary call. And then I call this routine via JNI. See this commit for example: http://svn.freepascal.org/cgi- bin/viewvc.cgi?view=rev&root=lazarus&revision=37692 ---------------------------------------------------------------------- ROCABDEL · 2012-06-20 18:33 thank you very much felipemdc for your availability. I tried this: Code: [Select]javaMethod_Bass_BASS_ChannelSetSync:= javaEnvRef^^.GetStaticMethodID(javaEnvRef, javaClass_Bass, 'BASS_ChannelSetSync', '(IIJLcom/un4seen/bass/BASS/SYNCPROC;L)I'); but the program crash when I run  for the second suggestion I do not think it's easy for me because it's the same library that she must have called my program.. I'll wait for the answer of your friends in android-ndk group maybe they will help us  if 'I manage to solve the problem I let you know.. for those who are interested in. Here are links to this audio library : -http://www.un4seen.com/  -Win32 http://www.un4seen.com/download.php?bass24  -Win64 http://www.un4seen.com/forum/?topic=9038.0  -OSX http://www.un4seen.com/download.php?bass24-osx  -Linux http://www.un4seen.com/download.php?bass24-linux  -ARM Linux http://www.un4seen.com/forum/?topic=13804.0     -Android http://www.un4seen.com/forum/?topic=13225.0  -iOS http://www.un4seen.com/forum/?topic=10910.0  -WinCE http://www.un4seen.com/forum/?topic=9534.0 thank you again and Sorry for my English . ---------------------------------------------------------------------- felipemdc · 2012-06-20 20:35 Quote from: ROCABDEL on June 20, 2012, 08:33:46 pmthank you very much felipemdc for your availability. I tried this: Code: [Select]javaMethod_Bass_BASS_ChannelSetSync:= javaEnvRef^^.GetStaticMethodID(javaEnvRef, javaClass_Bass, 'BASS_ChannelSetSync', '(IIJLcom/un4seen/bass/BASS/SYNCPROC;L)I'); but the program crash when I run  Your second L is wrong. It has no type. It should be: Ljava/lang/Object; Quotefor the second suggestion I do not think it's easy for me because it's the same library that she must have called my program.. I'll wait for the answer of your friends in android-ndk group maybe they will help us  To my surprise the answer was positive. It is possible to declare a new class and load it to the virtual machine. But I still don't dominate how to do that. It will probably be rather complex, but for me that's not a big deal. Here is the android-ndk thread about this: https://groups.google.com/forum/?fromgroups#!topic/android- ndk/SRgy93Un8vM ---------------------------------------------------------------------- ROCABDEL · 2012-06-21 20:27 I also asked in some French forums if anyone can give us a track, and I am trying to read some docs in English  http://www.pacifier.com/~mmead/jni/delphi/index.html http://java.sun.com/docs/books/jni/ http://docs.oracle.com/javase/1.4.2/docs/guide/jni/spec/jniTOC.html thank you again felipemdc and good luck