how to use Pointer in JNA.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int PTOsetApiOpt(int iOpt,void* lpValue,int iLen)
Parameters: iOpt: int
lpData: address from which data should be read.
iLen: length of data
returns int values : 0 as success or -1 as failure.
IN C
int PTOsetApiOpt(int iOpt,void* lpValue,int iLen)Parameters: iOpt: int
lpData: address from which data should be read.
iLen: length of data
returns int values : 0 as success or -1 as failure.Here's how i wrote it in Java..
void* lpValue can be any type. So in C it is expecting address of int value.
代码
public MyTest{
public interface MyLibrary extends Library {
public int PTOsetApiOpt(int iOpt,Pointer lpValue,int iLen);
}
public static void main(String[] args) {
MyLibrary myLib = (MyLibrary)MyLibrary.INSTANCE;
IntByReference ir = new IntByReference(1);
//got a result as 0 instead of -1.
int result = myLib.PTOsetApiOpt(1, ir.getPointer() , ir.getPointer().SIZE);
}