gpt4 book ai didi

java - C 等效 Java JNA 代码示例

转载 作者:行者123 更新时间:2023-12-02 07:57:48 24 4
gpt4 key购买 nike

我有这样的代码-

文件:输入.h

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

等效的 JNA Java 代码是什么?

最佳答案

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

关于java - C 等效 Java JNA 代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9392060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com