Re: [Ikvm-developers] IKVM / JNA not respecting structure order
Brought to you by:
jfrijters
From: Jeroen F. <je...@su...> - 2011-06-17 05:35:47
|
Hi Trevor, Java reflection does not guarantee member ordering and IIRC neither does javac (but in practise, both do order them in source order), so it's arguably a bit tricky of JNA to rely on this. Having said that, I did recently fix IKVM to maintain field ordering, see http://weblog.ikvm.net/?date=2011-05-18 Regards, Jeroen > -----Original Message----- > From: Bell, Trevor (E O C&S US) [mailto:tre...@si...] > Sent: Thursday, June 16, 2011 20:40 > To: ikv...@li... > Subject: [Ikvm-developers] IKVM / JNA not respecting structure order > > Hi, > > > > I have a Java app which uses JNA to call some Windows APIs. Some of > those APIs require structures. I have debugged a problem in IKVM and > found that it is reordering the members of the structure which causes my > Windows API calls to fail. I have converted JNA.jar and PLATFORM.jar to > .NET assemblies with IKVM. > > > > If you look at the struct SecBuffer, in the JNA platform source code, > here: > http://java.net/projects/jna/sources/svn/content/trunk/jnalib/contrib/pl > atform/src/com/sun/jna/platform/win32/Sspi.java?rev=1211 > > > > You will see that the order of the members matches that of the Windows > API: > > > > http://msdn.microsoft.com/en-us/library/aa379814(v=vs.85).aspx > > > > typedef struct _SecBuffer { > > ULONG cbBuffer; > > ULONG BufferType; > > PVOID pvBuffer; > > } SecBuffer, *PSecBuffer; > > > > > > IKVM, however, is re-ordering the members to: > > > > public NativeLong cbBuffer; > public Pointer pvBuffer; > public NativeLong BufferType; > > > > This would seem to be a bug or am I doing something wrong? > > > > Thanks! > > > > -Trevor > > |