24 messages in net.java.dev.jna.usersRe: [jna-users] Re: Mapping Struct to...
FromSent OnAttachments
thex...@email.comNov 1, 2008 1:46 am 
Timothy WallNov 1, 2008 5:04 am 
thex...@email.comNov 1, 2008 8:40 am 
Timothy WallNov 1, 2008 11:14 am 
Timothy WallNov 1, 2008 11:17 am 
thex...@email.comNov 2, 2008 12:30 am 
Timothy WallNov 2, 2008 7:42 am 
thex...@email.comNov 3, 2008 2:02 am 
Timothy WallNov 3, 2008 3:49 am 
thex...@email.comNov 3, 2008 4:51 am 
Timothy WallNov 3, 2008 6:22 am 
thex...@email.comNov 3, 2008 7:47 am 
Timothy WallNov 3, 2008 8:21 am 
thex...@email.comNov 3, 2008 11:19 pm 
Timothy WallNov 4, 2008 5:33 am 
Timothy WallNov 4, 2008 5:34 am 
thex...@email.comNov 4, 2008 2:33 pm 
Timothy WallNov 5, 2008 5:44 am 
thex...@email.comNov 5, 2008 8:15 am 
Timothy WallNov 5, 2008 9:19 am 
thex...@email.comNov 5, 2008 3:22 pm 
Timothy WallNov 5, 2008 7:00 pm 
thex...@email.comNov 6, 2008 3:36 am 
thex...@email.comNov 6, 2008 10:55 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] Re: Mapping Struct to JavaActions...
From:thex...@email.com (thex@email.com)
Date:Nov 4, 2008 2:33:58 pm
List:net.java.dev.jna.users

Hi Tim

Post your interface definition and usage. If it worked in your test dll but not in your real dll, you probably lost something in translation.

Test2.dll:

test2.h

#define FFACE_API __declspec(dllexport) struct INVENTORYITEM { short id; unsigned char index; unsigned char count; }; extern "C" FFACE_API INVENTORYITEM inventory(int index);

test2.cpp

#include "test2.h"

extern "C" INVENTORYITEM inventory(int index) { INVENTORYITEM item; item.count = 38; item.id = 1970; item.index = 30; return item; }

test2api.java

public INVENTORYITEM.ByValue inventory(int index); // public int inventory(int index);

public static class INVENTORYITEM extends com.sun.jna.Structure { public static class ByValue extends INVENTORYITEM implements
Structure.ByValue { } public short id; public byte index; public byte count; }

fface.h

#define FFACE_API __declspec(dllexport) struct INVENTORYITEM { short id; unsigned char index; unsigned char count; };

FFACE_API INVENTORYITEM GetInventoryItem(int index);

ffaceApi.java

public static class INVENTORYITEM extends com.sun.jna.Structure { public static class ByValue extends INVENTORYITEM implements
Structure.ByValue { } public short id; public byte index; public byte count; }

INVENTORYITEM.ByValue GetInventoryItem(int index); // int GetInventoryItem(int index);

My test2.dll mapped with the test2api using the structure return value returns
the valid values:

Test2Api$INVENTORYITEM$ByValue(allocated@0xa540e0 (4 bytes)) { short id@0=1970 byte index@2=30 byte count@3=38 }

My test2.ddl mapped with test2api using a int return value returns valid values
aswell:

639502258 (which is hex 0x261e07b2 featuring 38 (0x26), 30 (0x1e) and 1970
(0x07b2)).

My fface.dll mapped with the ffaceapi using the structure return value returns:

FFaceApi$INVENTORYITEM$ByValue(allocated@0x2c56ac8 (4 bytes)) { short id@0=0 byte index@2=0 byte count@3=0 }

My fface.dll mapped with the ffaceapi using the int return value returns:

639502258

One other thing. Try mapping an "int" return value on your test dll to see if you get the same results in that case as your real dll. If not, the dlls are not equivalent. If so, there's some overlooked difference in your Java code between the test and real cases.

I think thats the 2nd test with the test2api, right?

I did update the jna.jar to the latest before doing these tests.

Btw, the C# code I am using to verify the results from ffaceapi look alike this:

public static class FFACE { public static class Inventory { [DllImport("FFACE.dll", EntryPoint = "GetInventoryItem")] public static extern INVENTORYITEM InventoryItem(int index); } }

class Start { public static void Main() { INVENTORYITEM x = FFACE.Inventory.InventoryItem(1); Console.WriteLine(" item.id={0} index={1} count={2}\n", x.id,
x.index, x.count); } }

Is there anything missing? Don't think so.

Regards, Armin