

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
24 messages in net.java.dev.jna.usersRe: [jna-users] Re: Mapping Struct to...| From | Sent On | Attachments |
|---|---|---|
| thex...@email.com | Nov 1, 2008 1:46 am | |
| Timothy Wall | Nov 1, 2008 5:04 am | |
| thex...@email.com | Nov 1, 2008 8:40 am | |
| Timothy Wall | Nov 1, 2008 11:14 am | |
| Timothy Wall | Nov 1, 2008 11:17 am | |
| thex...@email.com | Nov 2, 2008 12:30 am | |
| Timothy Wall | Nov 2, 2008 7:42 am | |
| thex...@email.com | Nov 3, 2008 2:02 am | |
| Timothy Wall | Nov 3, 2008 3:49 am | |
| thex...@email.com | Nov 3, 2008 4:51 am | |
| Timothy Wall | Nov 3, 2008 6:22 am | |
| thex...@email.com | Nov 3, 2008 7:47 am | |
| Timothy Wall | Nov 3, 2008 8:21 am | |
| thex...@email.com | Nov 3, 2008 11:19 pm | |
| Timothy Wall | Nov 4, 2008 5:33 am | |
| Timothy Wall | Nov 4, 2008 5:34 am | |
| thex...@email.com | Nov 4, 2008 2:33 pm | |
| Timothy Wall | Nov 5, 2008 5:44 am | |
| thex...@email.com | Nov 5, 2008 8:15 am | |
| Timothy Wall | Nov 5, 2008 9:19 am | |
| thex...@email.com | Nov 5, 2008 3:22 pm | |
| Timothy Wall | Nov 5, 2008 7:00 pm | |
| thex...@email.com | Nov 6, 2008 3:36 am | |
| thex...@email.com | Nov 6, 2008 10:55 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread 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 Java | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Nov 3, 2008 3:49:02 am | |
| List: | net.java.dev.jna.users | |
On Nov 3, 2008, at 5:02 AM, thex...@email.com wrote:
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).
Sorry, I didn't get that. It sounds to me that the struct definition must be exported to dll aswell. Which infact depends shows its not. But with my poor knowledge of things going on really way down I guess I just missed the point.
The DLL won't carry any struct information. That's all generated by the compiler based on the header file.
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).
With a huge effort I managed to write a VC++ dll that exactly does like you suggested. Calling that dll from C# and VC itself returns the expected values. With JNA I get a Access Violation, with Native.setProtected(true) I get an Invalid memory access at at com.sun.jna.Pointer._getShort(). Changing the JNA definition to return an int instead of the structure returns an int consisting of the right values. I will have to verify this behaviour with the real dll still, but it looks promising and shows off the troubles I encountered quite well.
Can you verify JNA accordingly and report any bug to libffi?
Not sure when I'll get the chance. It's straightforward to add a new JNA test to verify the behavior (including a native method that returns an int-sized struct, if there isn't one already). That might've been easier than writing a vc++ dll :)
If a memory fault occurs with setProtected(true), you should be getting an exception rather than having the function return.
Not sure on why it is behaving differently. I am still using the PointerByReference instead of byte[] for string buffers. Gonna remove that and check it once more.
PointerByReference is "void **", which you use if you're expecting the native code to provide you with a value (the native code writes a "void *" into the pointer-sized memory you provide). byte[] is if you're providing the native code with a buffer in which to write. Use the wrong one and you'll get an access violation.







