

![]() | 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: |
5 messages in net.java.dev.jna.usersRe: [jna-users] Structure alignment a...| From | Sent On | Attachments |
|---|---|---|
| Steve Newell | Jul 3, 2008 3:23 pm | |
| Timothy Wall | Jul 3, 2008 3:37 pm | |
| Daniel Kaufmann | Jul 3, 2008 6:43 pm | |
| Bruno Medeiros | Jul 28, 2008 10:22 am | |
| Timothy Wall | Jul 28, 2008 11:59 am |

![]() | 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] Structure alignment and #pragma pack(2) | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Jul 28, 2008 11:59:32 am | |
| List: | net.java.dev.jna.users | |
On Jul 28, 2008, at 1:23 PM, Bruno Medeiros wrote:
Timothy Wall wrote:
On Jul 3, 2008, at 6:24 PM, Steve Newell wrote:
I am trying to interface with a third-party dll. I have a couple of questions.
1. The .h file that comes with the dll has a #pragma pack(4) at the top. Will this cause JNA problems? Or does it handle the structure alignment for me? If not, how do I specify the structure boundaries?
You can set structure alignment in your ctor if you need to. Usually you don't. I don't know how #pragma pack(4) differs from the default.
2. I am getting an "Unsupported return type ..." exception when I call a function.
I think that it is a Unicode/Ascii problem.
The dll provides both an Ascii and a Unicode interface, as well as defines structures that have both Ascii and Unicode versions. In every case, the only difference in the structures is the String members.
The W32API DEFAULT_OPTIONS takes care of String/WString details, so you can always just use String.
Is this correct?
Yes.
Secondly, the .h file declares entry points like this:
typedef C_Structure_A* (WINAPI *PFunctionA)(WORD &itemCount, DWORD &lastError); typedef C_Structure_W* (WINAPI *PFunctionW)(WORD &itemCount, DWORD &lastError);
If it's returning an array of structures, MyStructure as the return type and Structure.toArray(int size) to expand to the full array. It's not possible to do this automatically because JNA can't know the returned array size.
Hi. I've noticed this message and I wanted to post a related question regarding structure alignment:
I have some C structures which use #pragma pack(2) and I was wanting to know how to map that in JNA. For what I've seen there is no way.
I've used ALIGN_NONE so far, and it works because all my current struct members have 2 bytes of size or more. But know I need to map some more structures with 1-byte members (along with other size of members), and I can't map them correctly. (if I have a 1-byte member following by a 2-byte member, the 2-byte member will be aligned on a 1-byte boundary, instead of 2, which #pragma pack(2) enforces)
Any ideas?
You're correct, there currently isn't a #pragma pack(2) equivalent. Wouldn't be that hard to add it, since the actual alignment is maintained internally, and is left alone if the align type is ALIGN_NONE. Feel free to submit a patch with associated tests.
Without that patch, however, you'll have to manually align things by inserting dummy fields.
T.







