how to use Pointer in JNA.
时间:2010-09-05 来源:jrvin

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.
For example
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);
}
相关阅读 更多 +
排行榜 更多 +