

![]() | 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: |
6 messages in net.java.dev.jna.usersRe: [jna-users] need for full definit...| From | Sent On | Attachments |
|---|---|---|
| Schraagen, Marijn | Oct 24, 2008 10:26 am | |
| LYou...@gkservices.com | Oct 24, 2008 11:34 am | |
| Timothy Wall | Oct 24, 2008 11:42 am | |
| Luigi Bitonti | Oct 25, 2008 4:30 am | |
| Timothy Wall | Oct 25, 2008 1:26 pm | |
| Marijn Schraagen | Oct 27, 2008 9:08 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] need for full definition of nested structs? | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Oct 25, 2008 1:26:35 pm | |
| List: | net.java.dev.jna.users | |
On Oct 25, 2008, at 7:30 AM, Luigi Bitonti wrote:
Good (European) morning,
Wouldn't it be ok to declare the nested part as a Pointer?
Something like:
public interface dllproject extends Library{ public static class SQRTP1 extends Structure{ public Pointer basesquare; public double res; }
void square_plus1v2(SQRTP1 structuur, double arg); }
Only if the original declaration were thus:
struct SQRTP1 { struct SQBS* basesquare; double res; }
If that first field is not the same size as a pointer in native code, then declaring it to have the same size as a pointer will result in the wrong amount of memory allocated for the structure, and the wrong offset for the "res" field.
Regards Luigi
--- On Fri, 10/24/08, Schraagen, Marijn <Mari...@let.uu.nl> wrote: From: Schraagen, Marijn <Mari...@let.uu.nl> Subject: [jna-users] need for full definition of nested structs? To: use...@jna.dev.java.net Date: Friday, October 24, 2008, 6:27 PM
Good (European) evening,
I have a question about nested structs. I have searched the mailing list archives and the jna documentation but could not find the answer to this issue; I apologize if it has been discussed and I have missed it somehow.
The issue is closely related to the 'Nested Structure Definitions' section on https://jna.dev.java.net/javadoc/overview-summary.html. I have set up a small testing scenario with a dll containing the following structs and a function using them. The function calculates the square of the argument and adds 1.
typedef struct { double base1; double square1; } SQBS;
typedef struct { SQBS basesquare; double res; } SQRTP1;
DLLIMPORT void square_plus1v2(SQRTP1 *structuur, double arg){ structuur->basesquare.base1 = arg; structuur->basesquare.square1 = arg * arg; structuur->res = structuur->basesquare.square1 + 1; }
This is mapped in Java using the jna to the following:
public interface dllproject extends Library{ public static class SQBS extends Structure{ public double base1; public double square1; }
public static class SQRTP1 extends Structure{ public SQBK basesquare; public double res; }
void square_plus1v2(SQRTP1 structuur, double arg); }
and function call
dllproject lib = (dllproject) Native.loadLibrary("dllproject",dllproject.class); dllproject.SQRTP1 sq2 = new dllproject.SQRTP1(); lib.square_plus1v2(sq2, 6); System.out.println("Result: "+sq2.res);
This works perfectly fine.
However, here I have declared the nested struct SQBS with its own Structure. This struct is basically of no relevance to my Java program, where I only need to know the result (SQRTP1.res) variable. However, without the SQBS definition the program stops working correctly: now the value of SQBS.base1 is returned when asked for SQRTP1.res (this behaviour is documented by various sources).
Obviously, in this example it is no problem to declare the extra SQBS structure, and moreover, the functionality of the example could be implemented without nested structures or even without any structures at all. However, this is a test case: the end goal is to use a (3rd party) dll with a great amount of deeply nested structs in a hierarchy of header files. I need only the top-level functionality, and I wonder if it is neccesary to mirror the full definition of structs in my Java program.
Thank you in advance for any help or comments on this issue.
Kind regards,
Marijn Schraagen







