3 messages in net.java.dev.jna.usersRe: [jna-users] Mapping Struct to Java
FromSent OnAttachments
thex...@email.comOct 31, 2008 5:48 am 
Timothy WallOct 31, 2008 6:26 am 
thex...@email.comOct 31, 2008 6:29 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] Mapping Struct to JavaActions...
From:Timothy Wall (twal@dev.java.net)
Date:Oct 31, 2008 6:26:38 am
List:net.java.dev.jna.users

Your C function is returning a structure by value, therefore you need to declare a ByValue version of your structure.

class MyStructure extends Structure { public static ByValue extends MyStructure implements Structure.ByValue { } }

Then your function should return MyStructure.ByValue instead of MyStructure.

On Oct 31, 2008, at 8:48 AM, thex@email.com wrote:

Hi

Currently doing my very first steps between the worlds of C and Java. I got a header file that features structs and function calls of a specific dll I would like to access from within Java. Due to my lacking knowledge of C I decided to use JNA for integration purposes.

The standard calls work by now, I even managed to figure out the special way that strings get treaten in C. But now I am stuck on this call and its corresponding struct:

FFACE_API INVENTORYITEM GetInventoryItem(int index, DWORD PID = 0);

struct INVENTORYITEM { short id; unsigned char index; unsigned char count; };

My java mapping looks like this:

public interface FFaceApix extends Library { FFaceApix INSTANCE = (FFaceApix) Native.loadLibrary("FFACE", FFaceApix.class);

INVENTORYITEM GetInventoryItem(int index, int PID); } public static class INVENTORYITEM extends com.sun.jna.Structure { public short id; public byte index; public byte count; }

When accessing the mapped function I get an 'EXCEPTION_ACCESS_VIOLATION'. After having read lots of posts and checking out the JNA api aswell as the other documentation I still can't manage to make this work.

What did I not take care of with my mapping?

Regards, Armin