I need to learn how to handle the char**
in the C++ method below through Python ctypes.
I was doing fine calling other methods that only need single pointers by using create_string_buffer()
, but this method requires a pointer to an array of pointers.
ladybugConvertToMultipleBGRU32(
LadybugContext context,
const LadybugImage * pImage,
unsigned char** arpDestBuffers,
LadybugImageInfo * pImageInfo )
How do I create a pointer to an array of six create_string_buffer(7963648)
buffers in ctypes to pass to this C++ method for writing?
arpDestBuffers = pointer to [create_string_buffer(7963648) for i in xrange(6)]
Thank you for any help.
Both the answers given below work. I just didn't realize I had another problem in my code which prevented me from seeing the results right away. The first example is just as Luc wrote:
SixBuffers = c_char_p * 6
arpDestBuffers = SixBuffers(
*[c_char_p(create_string_buffer(7963648).raw) for i in xrange(6)] )
The second example coming from omu_negru's answer is:
arpDestBuffers = (POINTER(c_char) * 6)()
arpDestBuffers[:] = [create_string_buffer(7963648) for i in xrange(6)]
Both are accepted by the function and overwritten. Typing print repr(arpDestBuffers[4][:10])
before and after calling the function gives:
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x15\x10\x0e\xff\x15\x10\x0e\xff\x14\x0f'
which shows that the function successfully overwrote the buffer with data.