JNA Pointer转换为struct

时间:2010-08-17 07:57:09

标签: pointers casting jna

我在结构中有一个指针。我将结构指针传递给了这个指针。

但是我无法输回这个指向struct的指针。

public class Test
{

     //
     Pointer ptr = new Memory(4);
}

public class Temp extends Structure
{

     //

}

Test tst = new Test();
Temp tmp = new Temp();

tst.ptr = tmp.getPointer();

...

Temp newTmp = (Temp)tst.ptr.getPointer(); // This is not working.

1 个答案:

答案 0 :(得分:4)

您需要使用Structure(Pointer p)构造函数创建一个强制转换到内存的新结构:

Temp newTmp = new Temp(tst.ptr.getPointer());
相关问题