8 messages in net.java.dev.jna.usersRe: [jna-users] Question on variable ...
FromSent OnAttachments
Jay WaltersMay 12, 2008 9:42 am 
Timothy WallMay 12, 2008 9:52 am 
Jay WaltersMay 12, 2008 11:05 am 
Jay WaltersMay 12, 2008 11:12 am 
Timothy WallMay 12, 2008 12:05 pm 
Timothy WallMay 12, 2008 12:10 pm 
Jay WaltersMay 12, 2008 12:39 pm 
Timothy WallMay 12, 2008 2:05 pm 
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] Question on variable length structures in Win32Actions...
From:Jay Walters (jwal@computer.org)
Date:May 12, 2008 11:05:37 am
List:net.java.dev.jna.users

Ok, so I'll ditch the by reference for this case. I'll also let the variable
length stuff allocated at the end stay put for the moment.

So if I have a native function on windows like

int foo(PX * x);

and a structure X defined as

typdef struct _X {int a; int b; } X; typedef X * PX;

The function foo will allocate an X and put the ptr into the pointer to which x
refers (*x).

I can in Java create a class

class PX extends Structure { public int a; public int b; }

define foo as

int foo(PX x);

and away I go? How does JNA know that x is returned by reference and that it's
allocated in the native code? How would I distinguish from the case where I
actually pass a ptr to a PX object, rather than a ptr to a ptr to a PX object?

Now also, if my structure PX has a nested structure

class P1 extends Structure { public int a1; public int b1; }

public class PX extends Structure public P1 p1; public int a; public int b; }

Does this also 'just work' or do I need to do something else?

Cheers

jay