

![]() | 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.users[jna-users] need for full definition ...| 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: | [jna-users] need for full definition of nested structs? | Actions... |
|---|---|---|
| From: | Marijn Schraagen (mari...@let.uu.nl) | |
| Date: | Oct 27, 2008 9:08:43 am | |
| List: | net.java.dev.jna.users | |
Dear all,
Thanks for all the replies, it has been very helpful so far. I have decided to go with the suggestion of Levi Yourchuck, which was to write a wrapper dll in C with unnested definitions that calls the third party dll. This results in the chain java program~jna~C wrapper dll-3rd party dll. A bit of experimenting shows this approach to be promising. However, a new issue using the jna leaves me puzzled.
The testing is done without the 3rd party dll, using a simple main dll in the chain java~jna~C wrapper dll~C main dll. When I try to load the wrapper dll (called dllwrapper2.dll) with Native.loadLibrary, an error is thrown: UnsatisfiedLinkError: Unable to load library 'dllwrapper2': The specified module could not be found. This error can resolved in two ways. The first way is to remove function calls to the main dll from the wrapper dll. The second way is to copy the main dll into the same folder as the wrapper dll (note that all components, so the java program, jna.jar, wrapper dll and main dll are in separate folders). This shows that communication between both java/jna and wrapper as well as between wrapper and main dll is working, but the problem is that jna can't find the main dll through the reference in the wrapper dll.
The reason I think this is an issue with jna comes from some testing with a different chain: C console app-wrapper dll-main dll works fine (also these three components are in separate folders). Therefore the references/paths from wrapper to main which I set at compile time are ok, only the C console app has access to them whereas jna has not.
I have tried to solve this by supplying -Djna.library.path=path-to-wrapper;path-to-main (platform: WinXP, JRE6) to the JVM, however this does not work. As mentioned, everything works ok if I place wrapper and main into the same folder. This is not a problem for the testing environment, but with the end goal of using the 3rd party dll this is not a preferred solution.
Thanks agains for the input, I hope the above issue can be resolved too.
Regards,
Marijn Schraagen
Date: Sat, 25 Oct 2008 16:26:58 -0400 From: Timothy Wall <twal...@dev.java.net> Content-type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Subject: [jna-users] need for full definition of nested structs?
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







