I am working on a project where the only lib I have to communicate to is a .dll file and the resource I have is a C# working project with source code; I am using JNA to access native codes and I currently run into Invalid memory access when I call the method;
c# code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RSSlapInfo
{
public int fingerType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public RSPoint[] fingerPosition;
public int imageQuality;
public int rotation;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public int[] reserved;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RSSlapInfoArray
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public RSSlapInfo[] RSSlapInfoA;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RSPoint
{
public int x;
public int y;
};
RSSlapInfoArray slapInfoA = new RSSlapInfoArray();
IntPtr slapInfoArray;
int _size = Marshal.SizeOf(typeof(RSSlapInfoArray));
slapInfoArray = Marshal.AllocHGlobal(_size);
Marshal.StructureToPtr(slapInfoA, slapInfoArray, true);
On debug mode, I notice slapInfoArray value changes after the above call
My Java code:
public static class RSSlapInfo extends Structure
{
public RSSlapInfo(){}
public int fingerType;
public RSPoint[] fingerPosition = new RSPoint[4];
public int imageQuality;
public int rotation;
public int[] reserved =new int[3];
}
@Structure.FieldOrder({"RSSlapInfoA"})
public static class RSSlapInfoArray extends Structure implements Structure.ByValue
{
public RSSlapInfoArray() {
}
public RSSlapInfo RSSlapInfoA[] = new RSSlapInfo[4];
}
@Structure.FieldOrder({"x","y"})
public static class RSPoint extends Structure
{
public RSPoint(){
}
public int x;
public int y;
}
Currently stuck on the right way to convert this C# part of the code before I make the native call with slapInfoArray
RSSlapInfoArray slapInfoA = new RSSlapInfoArray();
IntPtr slapInfoArray;
int _size = Marshal.SizeOf(typeof(RSSlapInfoArray));
slapInfoArray = Marshal.AllocHGlobal(_size);
Marshal.StructureToPtr(slapInfoA, slapInfoArray, true);