C 等效 Java JNA 代码示例

发布于 2025-01-07 22:40:24 字数 184 浏览 4 评论 0原文

我有这样的代码-

file:input.h

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

等效的 JNA Java 代码是什么?

I have a code like this-

file:input.h

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

What is the equivalent JNA Java code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2025-01-14 22:40:24

就像这样,接口内部从抽象 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);
}

Simply like this inside an interface extends from an abstract Library or (if you are using Windows) a platform specific 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文