6 messages in net.java.dev.jna.usersRe: [jna-users] need for full definit...
FromSent OnAttachments
Schraagen, MarijnOct 24, 2008 10:26 am 
LYou...@gkservices.comOct 24, 2008 11:34 am 
Timothy WallOct 24, 2008 11:42 am 
Luigi BitontiOct 25, 2008 4:30 am 
Timothy WallOct 25, 2008 1:26 pm 
Marijn SchraagenOct 27, 2008 9:08 am 
Actions with this message:
Paste this link in email or IM:
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:LYou...@gkservices.com (LYou@gkservices.com)
Date:Oct 24, 2008 11:34:54 am
List:net.java.dev.jna.users

I'm speculating that the path of most productivity would be to write adapter style C code that has the methods you use delegating to the DLL and returns simple stuff so that your java code interfacing can avoid complexity. At least, that is what I'd naturally tend to do.

Levi Yourchuck Senior Programmer Analyst G&K Services Phone: 952 912 5828 www.gkservices.com Enhancing Image & Safety Through Innovation This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal.

"Schraagen, Marijn" <Mari@let.uu.nl> 10/24/2008 12:27 PM Please respond to use@jna.dev.java.net

To <use@jna.dev.java.net> cc

Subject [jna-users] need for full definition of nested structs?

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