title: Callback function pointer jna
body: <p>So i have native function in C declared as <code>int NgSetEvent (int event, long callback)</code>. long Callback represent the callback function pointer. Callback prototype is declared as <code>int oncodeline(int code, int documentid, char *string)</code>. The callback should be registered with method <code>NgSetEvent</code>. The problem is how to get pointer to that function which should be long or Nativelong? I have tried a lot of different aproaches but none of them gave a result. Callback was never invoked.</p>
  
  <p>I have tried to do like it says in <a href="https://stackoverflow.com/questions/17282785/turn-a-callback-into-a-pointer-in-jna">Turn a Callback into a Pointer in JNA</a>, but with no success. i don't know what to try anymore.
  Any help will be appreciated.</p>
  
  <p>OnCodeline </p>
  
  <pre><code>public interface OnCodeline extends Callback {
      int oncodeline (int code, int documentid, byte[] string);
  }
  </code></pre>
  
  <p>OnCodelineStruct</p>
  
  <pre><code>public class OnCodelineStruct extends Structure {
      public OnCodeline onc;
  
      @Override
      protected List getFieldOrder() {
          return Arrays.asList(new String[] { "onc" });
      }
  
  }
  </code></pre>
  
  <p>Main class</p>
  
  <pre><code>OnCodelineStruct onCodelinStruct;
  onCodelinStruct = new OnCodelineStruct();
              onCodelinStruct.onc = new OnCodeline() {
                  @Override
                  public int oncodeline(int code, int documentid, byte[] string) {
                      System.out.println("This IS a CALLBACK!");
                      return 0;
                  }
              };
  
  sbDll.NgSetEvent(0, onCodelinStruct.getPointer().getNativeLong(0));
  </code></pre>