我必须使用在第三方 dll 中定义的 c 函数
__declspec(dllimport) Init(DWORD id,HANDLE* handle);
JNAerate 生成了以下方法签名....
public static native int Init(int id,PointerByReference handle);
并将其用作
public interface Dll extends Library
{
public Dll _dll = (Dll)Native.LoadLibrary("dll_name");
public int Init(int id,PointerByReference handle);
}
public void init()
{
long hwnd = 0;
LongByReference lbr = new LongByRefrence(hwnd);
PointerByReference pbr = new PointerByReference();
pbr.setPointer(lbr.getPointer());
int ret = _dll.init(0x01,pbr);
}
但这会使 JVM 崩溃。有人可以告诉我在 JNA 中映射 void** 的适当方法吗?
最佳答案
PointerByReference.getValue()
为您提供被调用方“返回”的值。这是您可以用来初始化 HANDLE 值的值。无需“初始化”PointerByReference
。
public void init()
{
PointerByReference pbr = new PointerByReference();
int ret = _dll.init(0x01,pbr);
HANDLE handle = new HANDLE(pbr.getValue());
}
关于java - 相当于 HANDLE* 的 JNA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083056/