2 messages in net.java.dev.jna.usersRe: [jna-users] Problems on mapping ...
FromSent OnAttachments
Timothy WallApr 30, 2008 8:43 am 
jean-michel TApr 30, 2008 10:35 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] Problems on mapping C Struct and JNA Structure classActions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 30, 2008 8:43:34 am
List:net.java.dev.jna.users

On Apr 30, 2008, at 11:25 AM, Flávio wrote:

6 - DLL function:

Str1 TestFunction() { struct Str1 info; info.a=1; Beep(500,1000); info.b=2; Beep(1000,1000); return info; }

Where is "struct Str1 info" in memory? What happens to that memory when TestFunction returns? Does TestFunction return a structure by value or by reference (i.e. a pointer)? What is JNA expecting?

The one answer I'll give you is that by default JNA handles com.sun.jna.Structure as a pointer to struct (by reference). If you need by value semantics, you need to make a subclass of your Structure which implements ByValue (see the Structure javadcos and the javadoc overview for details).

If you're not familiar with how structures are used in C, I recommend you read the relevant chapter(s) in the K&R C book, or any other basic book on C programming.