

![]() | 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.usersRe: [jna-users] Structure with nested...| From | Sent On | Attachments |
|---|---|---|
| sylv...@free.fr | Dec 22, 2007 10:21 am | |
| Gabriele Forbiti | Dec 22, 2007 11:13 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: | Re: [jna-users] Structure with nested array of structures - maybe this can help | Actions... |
|---|---|---|
| From: | Gabriele Forbiti (4bi...@saitweb.it) | |
| Date: | Dec 22, 2007 11:13:34 am | |
| List: | net.java.dev.jna.users | |
Sylvain,
thanx for the tip, I may need to use it at some stage. Apparently the fix applied by Timothy to the Structure class does work. It wasn't working for me as I was using the latest svn jna.jar found in jna/jnalib/dist/ which however doesn't have the fix included. What I did was replace "Structure.class" in the jar with the one found in jna/jnalib/build/classes (automatically built by Eclipse). The "allocateMemory()" method doesn't fail now but I still have to find out whether my native dll reads the structure correctly. But that's a different story.
Au revoir!
Hi !
I also use a structure with a field being an array of structures. I found a solution which works for me. Hope this helps:
// here is my table of Structures PCF_PAIR_INFO ppi = new PCF_PAIR_INFO(); PCF_PAIR_INFO[] ppis = (PCF_PAIR_INFO[])ppi.toArray(nbPairs); // here I have a loop to init all the PCF_PAIR_INFO the way I want.
The PCF_PAIR_INFO class: public class PCF_PAIR_INFO extends Structure {
public float distance; //... all fields here public float co_tail;
public PCF_PAIR_INFO(){}
public void init(float z1, float z2, float v1, float v2){ this.distance = Math.abs(z2-z1); // filling every field here with this method. this.co_tail = 0f; write(); // this appears to be mandatory (I tried without...No success in further steps). } }
Back to my main Java class: PCF_DESCR pdescr = new PCF_DESCR(xxx, xxx, xxx, xxx, xxx, ppis[0].getPointer());
The PCF_DESCR class (the one with the nested structures): public class PCF_DESCR extends Structure {
// xxx fields... public Pointer pair;
npublic PCF_DESCR(){}
public PCF_DESCR(int xxx, int xxx, float xxx, int xxx, long xxx, Pointer p){ this.dimension = dim; this.vario_type = vt; this.missing_float = mf; this.missing_int = mi; this.nb_pairs = np; this.pair = p; } }
So in fact I give PCF_DESCR a pointer to the first element of my PCF_PAIR_INFO[] table (at least that is the way I understand it). I finally use a PCF_DESCR as an input of a C function. As I have the C sources, I put a good old fprinft in the C function before building the library: all elements from my PCF_PAIR_INFO[] are perfectly transmitted to the C when I call it from my Java code.
Cheers,
Sylvain.
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net
-- Il messaggio e' stato analizzato alla ricerca di virus o contenuti pericolosi da MailScanner, ed e' risultato non infetto.
-- Il messaggio e' stato analizzato alla ricerca di virus o contenuti pericolosi da MailScanner, ed e' risultato non infetto.







