title: JNI: passing bytes from c++ to java
body: <pre><code>HANDLE hFile = CreateFileA("C:\\myfile.zip", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  const int size = GetFileSize(hFile, NULL);
  char* buffer = new char[size];
  DWORD read;
  ReadFile(hFile, buffer, size, &amp;read, NULL);
  
  jclass cls = ...;
  jmethodID id = ...;
  
  jbyteArray arr = env-&gt;NewByteArray(size);
  env-&gt;GetByteArrayRegion(arr, 0, size, (jbyte*) buffer);
  env-&gt;CallStaticVoidMethod(cls, id, arr);
  </code></pre>
  
  <p>problem is that byte array contains just null bytes in java side, does anyone have idea why? </p>
  
  <p>EDIT: oh my bad it should be SetByteArrayRegion, sorry! all working now :)</p>