Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all JNA handle automatically it's own memory allocations which means that to following line is useless (and can damage the memory stack) :</p> <pre><code>myPointer.clear(size); //is this required to clear the memory and release the Pointer to the GC?? </code></pre> <p>Next it also automatically deal with native pointer types which means that both lines below are equivalent in your case :</p> <pre><code>public int myCfunc(Pointer s, IntByReference ls); public int myCfunc(myClass s, IntByReference ls); </code></pre> <p>and thus JNA will do <code>myObj.write();</code> and <code>read</code> for you.</p> <p>The following is 100% correct but I suggest that you log <code>len.getValue()</code> before and after your call to <code>myCfunc</code> (which sould give 3*4=12 ; 3 int of 4 bytes) : </p> <pre><code>int size = Native.getNativeSize(myClass.class); IntByReference len = new IntByReference(size); </code></pre> <p>If all of this is correct then you probably have an error in your structure's prototype.</p> <p>From my experience this is mostly due to an outdated C header file or an outdated library : </p> <ul> <li>You are using header version 2.0 which states that struct's values are int but your linking against library v1.0 which takes a bytes structure</li> <li>You are using header version 2.0 which states that struct's values are int but your linking against library v1.9 which takes two ints and a byte</li> </ul> <p>in the end your code should look like this :</p> <pre><code>public void foo(){ myWrapper wrapper = (myWrapper) Native.loadLibrary("SomeDllWithLegacyCode", myWrapper.class); myClass myObj = new myClass(); myObj.x = 1; myObj.y = 2; int size = Native.getNativeSize(myClass.class); IntByReference len = new IntByReference(size); //log len.getValue wrapper.myCfunc(myObj, len); //log len.getValue } </code></pre> <p>You can also try to <em>voluntarily</em> decrease len's value for debugging purposes eg :</p> <pre><code>IntByReference len = new IntByReference(size-1); IntByReference len = new IntByReference(size-2); IntByReference len = new IntByReference(size-3); //... IntByReference len = new IntByReference(size-11); </code></pre> <p>This won't do what you wan't but at least it should give you the correct "max len"</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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