How to obtain a new Pointer in Java?

前端 未结 3 1849
闹比i
闹比i 2021-01-18 00:07

How can I call a method with this method signature in C from JNA?

int open_device(context *ctx, device **dev, int index);

The last two line

3条回答
  •  深忆病人
    2021-01-18 00:15

    It appears that the JNA Pointer class has setPointer and getPointer methods to allow for multiple indirection, and the Memory class to actually "allocate" native objects. So you should be able to do something like: (I'm just guessing from the JNA docs, I've not tested this)

    Pointer pDev = new Memory(Pointer.SIZE); // allocate space to hold a pointer value
    // pass pDev to open_device
    Pointer dev = pDev.getPointer(0);        // retrieve pointer stored at pDev
    

提交回复
热议问题