

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
1 message in net.java.dev.jna.usersetting back tables of structures - it...| From | Sent On | Attachments |
|---|---|---|
| sylv...@free.fr | Dec 22, 2007 9:55 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | etting back tables of structures - it works !!! | Actions... |
|---|---|---|
| From: | sylv...@free.fr (sylv...@free.fr) | |
| Date: | Dec 22, 2007 9:55:54 am | |
| List: | net.java.dev.jna.users | |
Hi Timothy,
still about this problem of getting back structures filled by C...I finally worked this out, thanks to your responses.
Here is the solution in a few lines (maybe this can help other users). The C function I wanted to get results from is this one:
int GcGetPCFDirVar(PCF_DESCR *pcf, VARIO_DIR_PARAM *vario_dir_param, VARIO_LAG_INFO **lag_info_main, VARIO_LAG_INFO **lag_info_co, VARIO_LAG_INFO **lag_info_cross)
I do not come back on the first two arguments (used as inputs by the C function).
The three last arguments are my outputs, filled by the C function. So far I could not find a way to read the results...Frustrating ! Following your advice, here is what I wrote in my Java code:
PointerByReference pref_main = new PointerByReference(); PointerByReference pref_co = new PointerByReference(); PointerByReference pref_cross = new PointerByReference(); int retour = GcAPI.INSTANCE.GcGetPCFDirVar(pdescr, vdp, pref_main, pref_co, pref_cross);
// I am only interested in the first output, in fact... VARIO_LAG_INFO vli_main = new VARIO_LAG_INFO(pref_main.getValue()); VARIO_LAG_INFO[] vlis_main = (VARIO_LAG_INFO[])vli_main.toArray(nbLag);
// Just checking I get the good results (as within the C source using a good old fprintf(stderr, ...) during the computations). for (int i=0;i<nbLag;i++){ vlis_main[i].read(); System.err.println("Dist[" + i + "] = " + vlis_main[i].dist); }
Of course this implies writing the corresponding constructor for the type VARIO_LAG_INFO, now defined as follows:
package testClasses.GCAPI_structures;
import com.sun.jna.Pointer; import com.sun.jna.Structure;
public class VARIO_LAG_INFO extends Structure {
public long nb_pairs; public float dist; public float covariance; public float semi_vario; public float rho; public float mean_head; public float mean_tail; public float var_head; public float var_tail;
public VARIO_LAG_INFO(){}
public VARIO_LAG_INFO(Pointer p){ this.useMemory(p); } }
And that's it !
Again, thank's a lot for your help, Timothy. In fact this is just opening a whole lot of perspectives, because this C library I use is plenty of functions I definitely need. So I might come back ...well, next year in fact, for other information.
Anyway, I am glad to get rid of all that JNI + swig stuff, which was really limiting and painful ! JNA's just so great !
Bye.
Sylvain.







