[英]JNA Array Structure Pointer
I use java to call the .dll,Now I have a structure with a pointer variable "pBuf"in it.我使用java调用.dll,现在我有一个带有指针变量“pBuf”的结构。 I need to convert an array into a pointer and store it in this pointer variable.我需要将数组转换为指针并将其存储在此指针变量中。
Struct:结构:
public static class NET_DVR_BUF_INFO extends Structure {
public Pointer pBuf;
public int nLen;
@Override
protected List<String> getFieldOrder() {
return Arrays.asList("pBuf", "nLen");
}
}
Array:大批:
HCNetSDK.NET_DVR_VIDEOWALLWINDOWPOSITION[] net_dvr_videowallwindowpositions =
(HCNetSDK.NET_DVR_VIDEOWALLWINDOWPOSITION[]) new HCNetSDK.NET_DVR_VIDEOWALLWINDOWPOSITION().toArray(windows.size());
I need put net_dvr_videowallwindowpositions
to pBuf
.我需要把net_dvr_videowallwindowpositions
放到pBuf
。
What can i do?我能做什么?
JNA's Structure class has a getPointer()
method that returns the pointer to the structure that you need. JNA 的Structure类有一个getPointer()
方法,该方法返回指向您需要的结构的指针。 Since you have an array of structures, you want the pointer to the first element, index 0:由于您有一个结构数组,您需要指向第一个元素的指针,索引 0:
NET_DVR_BUF_INFO bufInfo = new NET_DVR_BUF_INFO();
bufInfo.pBuf = net_dvr_videowallwindowpositions[0].getPointer();
Since you defined the array using the Structure's toArray()
method, the other elements of the array will be in contiguous memory expected on the native side.由于您使用 Structure 的toArray()
方法定义了数组,因此数组的其他元素将位于本机端预期的连续内存中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.