title: Passing a byte array to a C++ function that accepts a void pointer
body: <p>I'm using boost::python to export some C++ functions that expect a <code>void*</code>. They interpret it as raw memory (an array of bytes) internally. Think <code>read</code> and <code>write</code> for some very special purpose device.</p>
  
  <p>How do I pass a Python <code>bytearray</code> to such a function?</p>
  
  <p>I have tried using <code>ctypes.c_void_p.from_buffer(mybytearray)</code> but this doesn't match the signature of the function.</p>
  
  <p>Here's the minimal example:</p>
  
  <pre><code>#include &lt;boost/python.hpp&gt;
  
  void fun_voidp(void*) {}
  
  BOOST_PYTHON_MODULE(tryit) {
      using namespace boost::python;
      def("fun_voidp", fun_voidp);
  }
  </code></pre>
  
  <p>And at the python side:</p>
  
  <pre><code>import tryit
  import ctypes
  b = bytearray(100)
  tryit.fun_voidp(b) # fail
  tryit.fun_voidp(ctypes.c_void_p.from_buffer(b)) # fail
  tryit.fun_voidp(ctypes.c_void_p.from_buffer(b).value) # fail
  </code></pre>