The length of an unknown array in python types

I am calling a C function using ctypesfrom Python. It returns a pointer to a structure in the memory allocated by the library (the application calls another function to free it later). I find it difficult to understand how to massage a function call according to ctypes. The structure is as follows:

struct WLAN_INTERFACE_INFO_LIST {
  DWORD               dwNumberOfItems;
[...]
  WLAN_INTERFACE_INFO InterfaceInfo[];
}

I used a subclass of Structure that looks like this:

class WLAN_INTERFACE_INFO_LIST(Structure):
    _fields_ = [
        ("NumberOfItems", DWORD),
        [...]
        ("InterfaceInfo", WLAN_INTERFACE_INFO * 1)
        ]

How to tell ctypes so that I can access the nth element of the InterfaceInfo array?

I can't use the excellent customresize()Scott function because I don't have memory ( Memory cannot be resized because this object doesn't own it).

+3
source share
1

resize():

def customresize(array, new_size):
    return (array._type_*new_size).from_address(addressof(array))
+3

Source: https://habr.com/ru/post/1753478/


All Articles