Note that there are some explanatory texts on larger screens.

plurals
  1. POError while passing array of structures conataining char array to native function using JNA
    primarykey
    data
    text
    <p>Here is my updated code after implementing suggestions. But still problems persist. </p> <pre><code>typedef struct S1{ char temp1[100]; char temp2[100]; }S1 ... int manipulateTemp(S1 s1Arr[] ); JNA interface looks like this public interface Add extends Library { Add INSTANCE = (Add) Native.loadLibrary("add", Add.class); public static class S1 extends Structure { public byte[] temp1 = new byte[100]; public byte[] temp2 = new byte[100]; public static class ByReference extends S1 implements Structure.ByReference { }; }; int manipulateTemp( S1[]); } // public static byte[] toByteArray(char[] a ,Charset c){ CharBuffer cBuffer = CharBuffer.wrap(a); ByteBuffer bBuffer = c.encode(cBuffer); return bBuffer.array; } //in main method Add lib = Add.INSTANCE; Add.S1.ByReference s1Ref = new Add.S1.ByReference(); Add.S1[] s1Arr = (Add.S1[])s1Ref.toArray(10); s1Ref.clear(); //initialize array for(int i =0;i&lt;s1Arr.lenth ;i++){ byte[] data = toByteArray("myString1".toCharArray,Charset.defaultCharSet System.arrarycopy(data,0, s1Arr[i].temp1,0,data.length); data = toByteArray("myString2".toCharArray,Charset.defaultCharSet System.arrarycopy(data,0, s1Arr[i].temp2,0,data.length); } // calling native function lib.manipulateTemp(s1Arr[]); After execution Exception in thread "main" java.lang.Error: Invalid memory access at com.sun.jna.Function.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:344) at com.sun.jna.Function.invoke(Function.java:276) at com.sun.jna.Library$Handler.invoke(Library.java:216) at com.sun.proxy.$Proxy0.manipulateTemp((Unknown Source) at LoanTest.newTestCalc.main(newTestCalc.java:288) </code></pre> <p>I even checked memory dump, structures are seems to be allocated stored correctly.Structure size is also correct = 200 bytes Any clues about this error?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload