简体   繁体   English

如何在JNA中从Java发送指向uint_32的指针?

[英]How to send a pointer to uint_32 from Java in JNA?

I have the following struct in C: 我在C中具有以下结构:

struct m{
   unit32_t *p; // array of uint32_t
};

And the following function: 和以下功能:

void print(struct *m);

How can I call this method with JNA and represent the structure in Java? 如何使用JNA调用此方法并用Java表示结构?

Nominally you'd do this: 名义上你会这样做:

public interface MyLib extends Library {
    class MyStruct extends Structure {
        public Pointer p;
        protected List getFieldOrder() {
            return Arrays.asList("p");
        }
    }
    void print(MyStruct s);
}

MyLib lib = Native.loadLibrary("mylib", MyLib.class);
MyStruct s = new MyStruct();
s.p = new Memory(length * 4);
lib.print(s);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM