Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Created August 6, 2012 19:34
Show Gist options
  • Save nicolamontecchio/3277840 to your computer and use it in GitHub Desktop.
Save nicolamontecchio/3277840 to your computer and use it in GitHub Desktop.
python ctypes - array conversion
#let's say f_TI is something like
#void blabla(int *data, int data_length);
#then
f_TI.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.c_int]
lll = [4,7,2,8]
lll_c = (ctypes.c_int * len(lll))(*lll)
f_TI(lll_c, len(lll))
@mytja
Copy link

mytja commented Aug 25, 2021

Thank you so much. I searched a whole internet for this ❤️

@kcvinker
Copy link

kcvinker commented Dec 22, 2022

Hi, how to convert an address of array into array with ctypes ?
num_tics = api.SendMessage(self._hwnd, con.TBM_GETNUMTICS, 0, 0 ) - 2
addr = api.SendMessage(self._hwnd, con.TBM_GETPTICS, 0, 0)

Now, this addr is a pointer to an array of 9 DWORDs. How do I get the data ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment