I’m Writing a Python ctypes wrapper for a DLL.
When an event occurs, the DLL attempts to call a callback function with the following prototype:
void Function(u8 *Data, u16 Length)
Essentially, it gives us a pointer to a buffer of raw data, and a length of that buffer.
I’m trying to find a method of receving and processing this data in my python code.
If I declare the ctypes function type as a char pointer:
TX_CALLBACK_FUNC_TYPE = CFUNCTYPE(None, c_char_p, c_int)
then the data is treated as a null terminated string, and I get truncated data if any 0x00 bytes exist in the buffer.
If I declare the ctypes function type as a void pointer:
TX_CALLBACK_FUNC_TYPE = CFUNCTYPE(None, c_void_p, c_int)
then I get a long integer value, which I assume is the address of the raw data – but I don’t know how to retrieve the data to use it in Python.
If I declare the ctypes function type as a POINTER to char:
TX_CALLBACK_FUNC_TYPE = CFUNCTYPE(None, POINTER(char), c_int)
then I get a ctypes.LP_c_char object, but I can’t figure out how to access the raw data in the object.
What’s the best way to access raw data in Python which is returned from a wrapped DLL?
You need a buffer: