C等效Java JNA代码示例

时间:2012-02-22 09:22:45

标签: java jna

我有这样的代码 -

文件:input.h

    struct Address{
       int a;
       int b;
    };
    void func(struct Address *a);    

等效的JNA Java代码是什么?

1 个答案:

答案 0 :(得分:2)

简单地说,界面内部扩展了抽象Library或(如果您使用的是Windows)特定于平台的com.sun.jna.win32.StdCallLibrary

public interface MyLibrary extends Library {

    /**
     * Native library instance.
     */
    MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary("MyLibrary", MyLibrary.class);

    /**
    struct Address{
       int a;
       int b;
    };      
    */

    public class Address extends Structure {
        public int    a;
        public int    b;
        public static class ByReference extends Address implements Structure.ByReference {

        };
        public static class ByValue extends Address implements Structure.ByValue {

        };        
    }; 

    /**
      void func(struct Address *a); 
    */
    void func(Address a);
}