

![]() | 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: |
2 messages in net.java.dev.jna.usersgetting a table of structures filled ...| From | Sent On | Attachments |
|---|---|---|
| sylv...@free.fr | Dec 21, 2007 4:21 am | |
| Timothy Wall | Dec 21, 2007 6:59 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: | getting a table of structures filled by C back to Java | Actions... |
|---|---|---|
| From: | sylv...@free.fr (sylv...@free.fr) | |
| Date: | Dec 21, 2007 4:21:16 am | |
| List: | net.java.dev.jna.users | |
Hi !
I am discovering JNA, and I must say it looks to be really great ! I have a small problem however. I am calling this C function from Java:
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)
PCF_DESCR and VARIO_DIR_PARAM are structures used as inputs. lag_info_main, lag_info_co and lag_info_cross are tables of structures returned by GcGetPCFDirVar. Here is how a VARIO_LAG_INFO is initialized in Java.
import com.sun.jna.Structure; public class VARIO_LAG_INFO extends Structure {
public static class ByReference extends VARIO_LAG_INFO implements Structure.ByReference { }
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(){ write(); } }
My problem is that I can not find a way to get back the output values from lag_info_main in Java. I put some fprintf (!) in the C source supposed to fill the VARIO_LAG_INFO[] tables of structures. Everything works perfectly on the C side: values like nb_pairs or semi_vario are correctly computed, but back in Java I get only zeros for all the fields. I also checked that the fields of the input structures (like PCF_DESCR) were ok when being read in the C: everything's fine.
I suppose my problems come from the way I initialise / get back the VARIO_LAG_INFO table. Here is the last try I wrote in Java:
VARIO_LAG_INFO.ByReference vli_main = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference vli_co = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference vli_cross = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference[] vlis_main = (VARIO_LAG_INFO.ByReference[])vli_main.toArray(nbLag); VARIO_LAG_INFO.ByReference[] vlis_co = (VARIO_LAG_INFO.ByReference[])vli_co.toArray(nbLag); VARIO_LAG_INFO.ByReference[] vlis_cross = (VARIO_LAG_INFO.ByReference[])vli_cross.toArray(nbLag);
int retour = GcAPI.INSTANCE.GcGetPCFDirVar(pdescr, vdp, vlis_main[0].getPointer(), vlis_co[0].getPointer(), vlis_cross[0].getPointer()); System.err.println("\nRetour GcAPI: " + retour);
for (int i=0;i<nbLag;i++){ vlis_main[i].read(); System.err.println("NbPair[" + i + "] = " + vlis_main[i].dist); // here I get zeros (but this value is != 0 and correct in C !) }
Any idea to get back correct values in my table of VARIO_LAG_INFO is welcome. Thank you so much in advance.
ST.







