简体   繁体   中英

JNA Array Structure Pointer

I use java to call the .dll,Now I have a structure with a pointer variable "pBuf"in it. 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 .

What can i do?

JNA's Structure class has a getPointer() method that returns the pointer to the structure that you need. Since you have an array of structures, you want the pointer to the first element, index 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM