Python isn't that hard you want it to be. This would look sort of:
imgdata = '\x04\x08\x14\x00\x01\x07\x0c\x00\x06\x07\x0e\x00'
testlib = ctypes.CDLL('path/to/my/lib/testlib.so')
dest = (c_uint8 * 12)()
testlib.grey(dest, imgdata, 12)
byte_array = bytearray(dest) # if you really neeed it
Edit: read voted up eryksun's comments (irrelevant since he deleted them). He explains how to make it right with your approach.
Oh, well, he insisted, so here's his code:
imgdata = '\x04\x08\x14\x00\x01\x07\x0c\x00\x06\x07\x0e\x00'
testlib = ctypes.CDLL('path/to/my/lib/testlib.so')
dest = (ctypes.c_char * len(imgdata))()
testlib.grey.restype = None
testlib.grey.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
testlib.grey(dest, imgdata, len(dest))
byte_array = bytearray(dest) # or just use dest.raw which is a python str
and his explanation:
c_char_p
is a char*
and an array of 12 char pointers is incorrect, and passing a pointer to that is doubly incorrect, and the only reason it didn't die in a ArgumentError
is that c_void_p
in argtypes
accepts a lot without complaining -- Python integers and strings, and ctypes pointers and arrays.