title: How to transfer a C structure to java by use of JNI?
body: <p>From C I am creating a DLL which is loaded in Java.
  I call some C functions from java and also call Java functions from C (whith uncomplex data types) - this is working fine.</p>
  
  <p>I struggle with the transfer of a C structure to Java.</p>
  
  <p>Here is a small example descriping what I want to do.
  It is not complete and maybe not correct because my problem is that I am not sure how to do it.</p>
  
  <p>My goal is to pass a structure from the type "StructType" from C to Java in order to use the values in the Java program.</p>
  
  <p><b>In C</b></p>
  
  <pre><code>typedef struct {
    unsigned char value1;
    unsigned char value2;
  } StructType;
  
  void passStructToJava(StructType* myStruct)
  {
    class cls;
    jmethodID mid;
  
    /* GlobalEnv, GlobalObj are globlal values which are already set */
    cls = (*GlobalEnv)-&gt;GetObjectClass(GlobalEnv, GlobalObj); 
    mid = (*GlobalEnv)-&gt;GetMethodID(GlobalEnv, cls, "receiveStructFromC", "(LPackage/StructType;)V");
  
    (*GlobalEnv)-&gt;CallVoidMethod(GlobalEnv, GlobalObj, mid, myStruct);
  }
  </code></pre>
  
  <p><b>In Java</b></p>
  
  <pre><code> public class StructType {
   public int value1; /* int because there is no uint8 type */
   public int value2;
  }
  
  public StructType mMyStruct;
  public StructType getMyStruct() {
    return mMyStruct;
  }
  public void setMyStruct(StructType myStruct) {
    mMyStruct = myStruct;
  }
  
  
  public void receiveStructFromC(StructType myStruct)
  {
    setMyStruct(myStruct);
  }
  </code></pre>
  
  <p>Thanks in advance for your help.<br>
  Steffen</p>