title: JNA non-const String member of struct
body: <p>I have a C function that expects a struct that contains a non-const String.</p>
  
  <pre><code>typedef struct _A {
    char* str;
  } A;
  
  void myFunc(A* aptr) { ... }
  </code></pre>
  
  <p>I've tried for a long time to pass this thing via JNA but didn't manage so far.</p>
  
  <pre><code>public class A extends Structure {
    public String str;
    protected List getFieldOrder() { ...
  }
  </code></pre>
  
  <p>doesn't work because String will be turned into a const char* instead of char* which I need.</p>
  
  <pre><code>public class A extends Structure {
    public byte[] str;
    protected List getFieldOrder() { ...
  }
  </code></pre>
  
  <p>doesn't work because the byte array inside a struct gets turned into contiguous memory and not a pointer.</p>
  
  <p>I know I can do it by using <code>Memory</code> and copying the String over. But I can't imagine that this is the preferred way to do it.</p>
  
  <p>I also tried something like</p>
  
  <pre><code>public class NonConstStringMember extends Structure {
    public static class ByReference extends NonConstStringMember implements Structure.ByReference {}        
    public byte[] stringMember;
    protected List getFieldOrder() { ...
  }
  
  public class A extends Structure {
    public NonConstStringMember.ByReference str;
  }
  </code></pre>
  
  <p>but it doesn't work either, maybe because of alignment issues.</p>
  
  <p>What is the preferred way to do this with JNA?</p>