

![]() | 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: |
4 messages in net.java.dev.jna.usersRe: [jna-users] struct vs &struct vs ...| From | Sent On | Attachments |
|---|---|---|
| bb...@cox.net | Jul 16, 2007 9:21 am | |
| Timothy Wall | Jul 16, 2007 11:54 am | |
| bb...@cox.net | Jul 17, 2007 4:45 am | |
| bb...@cox.net | Jul 17, 2007 4:53 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] struct vs &struct vs struct * | Actions... |
|---|---|---|
| From: | bb...@cox.net (bb...@cox.net) | |
| Date: | Jul 17, 2007 4:45:17 am | |
| List: | net.java.dev.jna.users | |
---- Timothy Wall <twal...@dev.java.net> wrote: [...]
In almost all C programs, the only difference is whether you pass the structure ("by value") or a pointer to the structure. Usually if you pass the structure by value, changes made by the called function won't be visible to the caller. Structure by value is also not currently supported by JNA, at least not directly, since it's highly dependent on compiler specifics and has a whole host of corner cases that'd be a pain to support, and the usage is not that common.
[...]
Most compilers will usually pass small structs on the stack, assuming they fit in a stack slot. JNA does not explicitly support struct by value (i.e. the first argument).
Unfortunately, my example is a reasonable mimic of my actual plight: I'm writing a JNA interface for a library supplied by somebody else (i.e. I can't change it), and the fickle people who wrote it have a function that takes as parameters (among other things):
a struct pointers to structs a pointer to a struct containing a pointer to an array of structs
Yay!
So, after your advice and corrections maybe I've got everything sorted out besides the struct that they are passing in "by value". (Yes, I understand all that nomenclature quite well.)
The struct in question contains just four pointers, and in the short term, all four I think can be safely set NULL. So, for purposes of forcing this to work with JNA, can I perhaps treat the function:
extern int f(struct A a, struct B *b, struct C *c); instead something like extern int f(void *a1, void *a2, void *a3, void *a4, struct B *b, struct C *c); ?
I don't know how the .dll was compiled. I wrote a simple C program that calls that function, and after compiling and linking it to the .dll using cygwin's gcc, it seemed to work. (Uh, maybe I should check the outputs more thoroughly than "it did not crash when I ran it".)
Is there any way to know if this will work? (Is there any way to discover what policy the compiler used for this struct-passed-by-value?)
And if I go with the above (and if I've guessed correctly), then is it just class B extends Structure {...}; class C extends Structure {...}; int f(Pointer a1, Pointer a2, Pointer a3, Pointer a4, B b, C c); and at the call is it B b = new B(); C c = new C(); int rv = f(null,null,null,null,b,c); ?
This passed-by-value struct problem would explain why Hot-Spot has been falling over dead. (Not that I'm not making other mistakes...)







