title: Returning jintArray from JNI
body: <p>I'm trying to return a jintArray from C++ to Java, but the application seems to hang in the JNI call. I have stripped the problem down to the creation and population of the jintArray, although I'm not receiving any errors. Any help is appreciated.</p>
  
  <p>Test project to make sure everything works:</p>
  
  <pre><code>include "stdafx.h"
  include "windows.h"
  include &lt;vector&gt;
  include &lt;iostream&gt;
  include &lt;jni.h&gt;
  
  using namespace std;
  
  std::vector&lt;jint&gt; childWindows;
  
  BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
      childWindows.push_back((jint) hwnd);
      return TRUE;
  }
  
  jint* getChildWindows(HWND hWnd) {
      childWindows.clear();
      ::EnumChildWindows(hWnd, EnumChildProc, NULL);
  
      int len = static_cast&lt;int&gt;(childWindows.size());
  
      jint values[100];
      std::copy(childWindows.begin(), childWindows.end(), values);
  
  
      for (std::vector&lt;jint&gt;::const_iterator i = childWindows.begin(); i != childWindows.end(); ++i) {
          std::cout &lt;&lt; (HWND)*i &lt;&lt; ' ';
      }
      //env-&gt;SetIntArrayRegion(childeren, 0, len, values);
      return values;
  }
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      getChildWindows((HWND)1377258);
  
      std::cout &lt;&lt; " | Windows count: " &lt;&lt; childWindows.size() &lt;&lt; " ";
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>000D0550 000B04F2 001C047A 0002055E 00020558 00010564 0007054E
    00050570 00060512  000C04E0  | Windows count: 10</p>
  </blockquote>
  
  <p>Java code:</p>
  
  <pre><code>    System.out.println("Get child windows");
      System.out.println("Main handle: " + getHandle());
      final int[] handles = getChildWindows();
      System.out.println("Done getting childs");
  </code></pre>
  
  <p>Java output:</p>
  
  <blockquote>
    <p>Starting test child windows</p>
    
    <p>Get child windows</p>
    
    <p>Main handle: 525978</p>
  </blockquote>
  
  <p>JNI code:</p>
  
  <pre><code>JNIEXPORT jintArray JNICALL Java_main_getChildWindows(JNIEnv *env, jclass c) {
      childWindows.clear();
      ::EnumChildWindows(hWnd, EnumChildProc, NULL);
  
      int len = static_cast&lt;int&gt;(childWindows.size());
      jintArray childeren = env-&gt;NewIntArray(len);
  
      jint values[100];
      std::copy(childWindows.begin(), childWindows.end(), values);
  
      env-&gt;SetIntArrayRegion(childeren, (jsize)0, (jsize)len, values);
      //env-&gt;ReleaseIntArrayElements(childeren, values, 0);
      return childeren;
  }
  </code></pre>