title: PointerByReference not returning value
body: <p>I'm trying to call a C++ function from Java via JNA.  I want to pass in a string, and get a string back.  This is done by using an in parameter and an out parameter.  I use <code>PointerByReference</code> to represent the <code>char**</code> out parameter. The call to C++ works, but the <code>PointerByReference</code> is null after the call.  </p>
  
  <p>I based my code on the  <a href="https://github.com/twall/jna/blob/master/www/ByRefArguments.md" rel="nofollow">PointerByReference</a> docs.  Any ideas what I'm doing wrong?</p>
  
  <p>I've added print statements to the C++ to make sure it's not not setting the pointer to null, and it's definitely not.  So some in my use of JNA must be wrong. But what?</p>
  
  <p><strong>C++ code</strong></p>
  
  <pre class="lang-c prettyprint-override"><code>void processRequest(char* input, char** output, int* outputLength)
  {
  
      // Variable output size from processInput
  
      std::string sOutput = processInput(input);
  
  
      char* results = new char[sOutput.length() + 1];
  
      strncpy(results, sOutput.c_str(), sOutput.length());
  
      results[sOutput.length()] = '\0';
  
  
      output = &amp;results;
  
      outputLength = new int(strlen(results) + 1);
  
  }
  </code></pre>
  
  <p><strong>Java code</strong></p>
  
  <p>Which is called by java like so:</p>
  
  <pre><code>public class RunRequestT1 {
      private static final Logger log = LoggerFactory.getLogger(MyLibWrapperImpl.class);
  
      static boolean envVarsSetupDone = false;
  
      static interface MyLib extends Library {
  
          MyLib INSTANCE = (MyLib) Native.loadLibrary("N:\\sys1\\sys1_dist\\MyLib\\MyLib9.8.Q.P3.G15.T\\bin\\MyLib.dll", MyLib.class);
  
          public void processRequest(String request, PointerByReference bufp, IntByReference lenp);
  
          public void clearMemoryPtr(PointerByReference bufp, IntByReference lenp);
      }
  
      public static void main(String[] args) throws IOException {
  
          System.out.println("sys1: Reading request");
          String request = FileUtils.readFileToString(new File("C:\\dev\\prj\\single-request.xml"), "UTF-8");
  
          System.out.println("sys1: Pricing request");
          String response = processRequest(request);
  
          System.out.println(response);
  
      }
  
      public static String processRequest(String request) {
  
          System.out.println("sys1: prepare args");
          // code based on https://github.com/twall/jna/blob/master/www/ByRefArguments.md
          PointerByReference bufp = new PointerByReference();
          IntByReference lenp = new IntByReference();
  
          System.out.println("sys1: making call");
          MyLib.INSTANCE.processRequest(request, bufp, lenp);
  
          System.out.println("reading response");
          System.out.println("bufp: " + bufp.getValue());
          System.out.println("lenp: " + lenp.getValue());
          Pointer p = bufp.getValue();
          byte[] buffer = p.getByteArray(0, lenp.getValue());
          String response = Native.toString(buffer);
          //String response = p.getString(0);
  
          // de-allocate memory buffer
          System.out.println("cleaning memory");
          MyLib.INSTANCE.clearMemoryPtr(bufp, lenp);
          return response;
      }
  }
  </code></pre>
  
  <p><strong>Stdout</strong></p>
  
  <p>And when I call it, I get results like this:</p>
  
  <pre><code>sys1: Reading request
  sys1: Pricing request
  sys1: prepare args
  sys1: making call
  reading response
  bufp: null
  lenp: 0
  Exception in thread "main" java.lang.NullPointerException
      at com.calyon.gcm.MyLibwrapper.main.RunRequestT1.priceRequest()
      at com.calyon.gcm.MyLibwrapper.main.RunRequestT1.main()
  </code></pre>
  
  <p>I've tried to keep it minimal, and indeed there is not a lot going on. </p>
  
  <p>I've tested with JNA versions 3.4 and 3.5</p>