I generated a JNA from a header file and here is the two functions of interest.
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.
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. The code executes but I receive an FT_INVALID_HANDLE, which is returned by FT_Close.
Here is the java code
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. What is the proper way to pass from void** to void* in java using JNA?
Turns out the error was on
handle = pbr.getPointer();
It should be
handle = pbr.getValue();