ctypes on Windows question: How to access an array of uint32_t exported from a DLL?

Eryk Sun eryksun at gmail.com
Mon Jun 7 12:33:52 EDT 2021


On 6/6/21, pjfarley3 at earthlink.net <pjfarley3 at earthlink.net> wrote:
>
> On a Windows 10 platform (python 3.8.9 and 3.9.5), how do I use ctypes to
> access an array of uint32_t's exported from a DLL?
> ...
> __declspec(dllexport) extern uint32_t array_name[128];

A ctypes data type has an in_dll() method [1] that returns an instance
of the type that references data in a shared library (DLL). It takes a
CDLL instance for the shared library and the exported symbol name. For
example:

    data = (ctypes.c_uint32 * 128).in_dll(library, "array_name")

---
[1] https://docs.python.org/3/library/ctypes.html#ctypes._CData.in_dll


More information about the Python-list mailing list