In Python using ctypes for passing pointer to struct pointer to C function
<p>In a C library there's:</p>

<pre><code>typedef struct A *  B;
int create_b(B* b);
</code></pre>

<p>and using ctypes I need the Python equivalent to:</p>

<pre><code>B b;
create_b(&amp;b)
</code></pre>

<p>The struct A is implemented in Python as <code>class A(ctypes.Structure)</code>.</p>

<p>So, I tried:</p>

<pre><code>b = ctypes.POINTER(A)
lib.create_b(ctypes.byref(b))
</code></pre>

<p>but it's not working.  There are many similar questions, but none I tried helped.</p>

<p>This line</p>

<pre><code>b = ctypes.POINTER(A)
</code></pre>

<p>is just setting <code>b</code> to refer to the same type <code>ctypes.POINTER(A)</code>, where what is really wanted is a variable constructed with that type.  The line is missing the parentheses at the end:</p>

<pre><code>b = ctypes.POINTER(A)()
</code></pre>

python c pointers ctypes