title: Passing a pointer to a structure (StructureByReference) in to C code, How to access that data again?
body: <p>I am passing the following Test Structure from Java in Android to a native C function in a shared library:</p>
  
  <pre><code>@Structure.FieldOrder({"testDouble", "testInt", "testPointer"})
  public class Test extends Structure implements Structure.ByReference {
  
      public double testDouble;
      public int testInt;
      public Pointer testPointer;
  
  
      public Test(double testDouble, int testInt, Pointer testPointer) {
              this.testDouble = testDouble;
              this.testInt = testInt;
              this.testPointer = testPointer;
  
      }
  
      Getters &amp; Setters...
  </code></pre>
  
  <p>The native C code handles the structure as:</p>
  
  <pre><code>    void Test(double extraDouble, Test *TestResult)
  </code></pre>
  
  <p>The Native C code takes the pointer to the <code>TestResult</code> and populates all the fields.</p>
  
  <p>I then need to be able to access that data back in the Java code - i.e access the Test Object and read the data <code>testDouble</code>, <code>testInt</code> and the data at <code>testPointer</code>, which is a <code>double[]</code>. The <code>TestResult</code> object is not passed back by the function; as you can see, it is just overwritten in the memory I assume.</p>
  
  <p>I understand how to send the data; however, when I try to access the object again by the value back in Java, after the population has supposed to have taken place, I just get zero data - as if it is a brand new object, not the original one with the now populated data.</p>
  
  <p>How can I access the data that my C code should have populated? I.e. I think access the memory at that pointer again?</p>
  
  <p>I assume in the Native C code it simply overwrites that memory block with the new data and then I have to find some way to be able to access that block of data back in java and rebuild my Test Structure. Please correct me if any of my presumptions are incorrect.</p>
  
  <p>If you need any clarification please let me know.</p>
  
  <p>The C struct is just:</p>
  
  <pre><code>typedef struct {
    double testDouble;
    int testInt;
    double testPointer[3];
  } Test;
  </code></pre>