how to use Pointer in JNA.

代码
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);
}

 
posted @ 2010-09-05 10:08  jrvin  阅读(1576)  评论(0编辑  收藏  举报