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:Timothy Wall (twal@dev.java.net)
Date:Nov 2, 2008 7:42:49 am
List:net.java.dev.jna.users

On Nov 2, 2008, at 2:30 AM, thex@email.com wrote:

Is there any way to "extract" information about the functions and structs from the corresponding library FFACE.lib? I got the dll, the header file and the library. As a matter of fact the header is not complete and outdated I guess probably nobody is using it. I found a C# file that defines all function calls including the one of the header file plus about 30 more than that.

The information should be in the C# file. You can also use the "depends.exe" tool, which shows you function names and dll dependencies.

See what "sizeof(INVENTORYITEM)" returns in C#, and ensure that Structure.size() returns the same thing in Java. If there are any #pack directives in the header to change the structure layout, it might also cause the size to be different than the default.

sizeof() not usuable on INVENTORYITEM - it says INVENTORYITEM does not have a fixed size. Had to determine the size of the return value with System.Runtime.InteropServices.Marshal.SizeOf(). The estimation in Java resulted in a size of 4 - C# told me the same value.

You can't compile a struct-by-value return without the full structure definition -- the compiler implicitly copies the return value (usually by passing the called function the address of the struct memory to which to write).

There may be a bug in returning struct values of small size; you can verify this by making your own DLL function with identical signature to the original, but which returns known values in the struct. Alternatively you could declare the function as returning "int" and extracting the fields manually (if this works, it would suggest a bug in libffi's handling of small structs on w32).

I did start using Native.setProtected(true) - either because of this or because of multiple tests done in a short period I had to encounter that the returned structure may contain random values. Up to 5 runs out of 10 features random negative numbers in the return value.

If a memory fault occurs with setProtected(true), you should be getting an exception rather than having the function return.