

![]() | 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.usersRe: getting back tables of structures...| From | Sent On | Attachments |
|---|---|---|
| Timothy Wall | Dec 21, 2007 2:53 pm |

![]() | 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: | Re: getting back tables of structures - still can't find a way out | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Dec 21, 2007 2:53:09 pm | |
| List: | net.java.dev.jna.users | |
On Dec 21, 2007, at 12:35 PM, sylv...@free.fr wrote:
Hello Timothy,
I am still struggling with this call:
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 must get THREE outputs from GcGetPCFDirVar: - lag_info_main - lag_info_co - lag_info_cross
Fields of a VARIO_LAG_INFO are the following: 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;
All my tables are tables of CONTIGUOUS structures each element being of type VARIO_LAG_INFO.
To initialise the three outputs, I do the following in my Java code: VARIO_LAG_INFO vli_main = new VARIO_LAG_INFO(); VARIO_LAG_INFO vli_co = new VARIO_LAG_INFO(); VARIO_LAG_INFO vli_cross = new VARIO_LAG_INFO(); VARIO_LAG_INFO[] vlis_main = (VARIO_LAG_INFO[])vli_main.toArray (nbLag); VARIO_LAG_INFO[] vlis_co = (VARIO_LAG_INFO[])vli_co.toArray(nbLag); VARIO_LAG_INFO[] vlis_cross = (VARIO_LAG_INFO[])vli_cross.toArray (nbLag);
I know in advance nbLag, the length of each vlis_xxx.
Here is my call to the C function: int retour = GcAPI.INSTANCE.GcGetPCFDirVar(pdescr, vdp, vlis_main, vlis_co, vlis_cross);
I gave a try to what you gave me: PointerByReference pref = new PointerByReference();
// call your function here, with a pointer by reference for each of the last three arguments
Pointer p = pref.getValue(); VARIO_LAG_INFO vli = new VARIO_LAG_INFO(); vli.useMemory(p);
vli.toArray(nbLag) at this point should convert the returned memory into a contiguous array of struct.
But: 1) I am not sure where exactly I should put these lines. 2) In fact useMemory seems to be recognized only in my VARIO_LAG_INFO class, and can not be used outside. And if I use useMemory in VARIO_LAG_INFO, I get an error from Structure.java: Exception in thread "main" java.lang.NullPointerException at com.sun.jna.Structure.useMemory(Structure.java:184) at com.sun.jna.Structure.useMemory(Structure.java:175) at testClasses.GCAPI_structures.VARIO_LAG_INFO.<init> (VARIO_LAG_INFO.java:24)
You can always define a ctor which takes a Pointer argument and calls useMemory.
3) ... Last but not least, I still can not read my output values in Java...
Any help welcome. I am sure I sould not be too far from success, but last steps are a bit hard for me.
Once you've called useMemory, call Structure.read(), which copies the contents of native memory into your java object. toArray() will take care of this automatically for all structures after the first.







