Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a Python ctypes pointer to an array of pointers
    primarykey
    data
    text
    <p>I need to learn how to handle the <code>char**</code> in the C++ method below through Python ctypes. I was doing fine calling other methods that only need single pointers by using <code>create_string_buffer()</code>, but this method requires a pointer to an array of pointers.</p> <pre><code>ladybugConvertToMultipleBGRU32( LadybugContext context, const LadybugImage * pImage, unsigned char** arpDestBuffers, LadybugImageInfo * pImageInfo ) </code></pre> <p>How do I create a pointer to an array of six <code>create_string_buffer(7963648)</code> buffers in ctypes to pass to this C++ method for writing?</p> <pre><code>arpDestBuffers = pointer to [create_string_buffer(7963648) for i in xrange(6)] </code></pre> <p>Thank you for any help.</p> <hr> <p>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:</p> <pre><code>SixBuffers = c_char_p * 6 arpDestBuffers = SixBuffers( *[c_char_p(create_string_buffer(7963648).raw) for i in xrange(6)] ) </code></pre> <p>The second example coming from omu_negru's answer is:</p> <pre><code>arpDestBuffers = (POINTER(c_char) * 6)() arpDestBuffers[:] = [create_string_buffer(7963648) for i in xrange(6)] </code></pre> <p>Both are accepted by the function and overwritten. Typing <code>print repr(arpDestBuffers[4][:10])</code> before and after calling the function gives:</p> <pre><code>'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' '\x15\x10\x0e\xff\x15\x10\x0e\xff\x14\x0f' </code></pre> <p>which shows that the function successfully overwrote the buffer with data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload