I am new to ctypes but I want to create a callback function with the following callback signature:
def autosetup_callback(p0, p1, p2):
"""This is my callback function signature
void(__stdcall *pGUIFunction)(SIndex sIndex, unsigned int statusFlag, unsigned int, const char message[512])
"""
print('autosetup arguments', p0, p1, p2)
sn= c.c_uint(0)
autosetup_cb_format = c.CFUNCTYPE(sn, c.c_uint, c.c_uint, c.c_char)
When this callback is called, I get the following errors:
File "_ctypes/callbacks.c", line 257, in 'converting callback result'
TypeError: an integer is required (got type NoneType)
settings: values p1,p2,p3: 0 0 0
autosetup arguments 0 0 b'\x18' ### This is what the callback should print
Exception ignored in: <function autosetup_callback at 0x000001E3D4135A60>
Any ideas?
There's some inconsistency in your example:
__stdcall
should useWINFUNCTYPE
notCFUNCTYPE
.sn
is an instance, not a type. The first parameter of the callback definition is the return value (void
,None
in Python).char[512]
(decays tochar*
soc_char_p
is needed in the callback definition.Here's a working example. Given:
test.c
test.py
Output: