简体   繁体   English

JNA:void **和void之间的转换*

[英]JNA: conversion between void** and void*

I generated a JNA from a header file and here is the two functions of interest. 我从头文件生成了一个JNA,这是感兴趣的两个函数。

FT_STATUS FT_OpenEx(void* pArg1,int Flags,void** pHandle);

FT_STATUS FT_Close(void* ftHandle);

And here is how it got converted in the JNA. 以下是它如何在JNA中转换。

int FT_OpenEx(String pArg1, int Flags, PointerByReference pHandle);

int FT_Close(Pointer ftHandle);

I call FT_OpenEx passing a PointerByReference and then get the pointer and pass it to FT_Close. 我调用FT_OpenEx传递一个PointerByReference,然后获取指针并将其传递给FT_Close。 The code executes but I receive an FT_INVALID_HANDLE, which is returned by FT_Close. 代码执行但我收到FT_INVALID_HANDLE,由FT_Close返回。

Here is the java code 这是java代码

 Pointer handle;
 PointerByReference pbr = new PointerByReference();
 int status = Ftd2xxLibrary.INSTANCE.FT_OpenEx(serialNumber, Ftd2xxLibrary.FT_OPEN_BY_SERIAL_NUMBER, pbr);

 handle = pbr.getPointer();

 status = Ftd2xxLibrary.INSTANCE.FT_Close(handle);

My guess is that the pointer I pass on to FT_Close is not actually pointing at the right address. 我的猜测是,我传递给FT_Close的指针实际上并没有指向正确的地址。 What is the proper way to pass from void** to void* in java using JNA? 使用JNA在java中从void **传递到void *的正确方法是什么?

Turns out the error was on 结果证明错误已经开启

handle = pbr.getPointer();

It should be 它应该是

handle = pbr.getValue();

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

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