That worked.  Many thanks Eryk.
Rob

On 30/06/2022 23:45, Eryk Sun wrote:
On 6/30/22, Rob Cliffe via Python-list <python-list@python.org> wrote:
AKAIK it is not possible to give ctypes a bytearray object and persuade
it to give you a pointer to the actual array data, suitable for passing
to a DLL.
You're overlooking the from_buffer() method. For example:

     >>> ba = bytearray(10)
     >>> ca = (ctypes.c_char * len(ba)).from_buffer(ba)
     >>> ca.value = b'spam&eggs'
     >>> ba
     bytearray(b'spam&eggs\x00')

Note that the bytearray can't be resized while a view of the data is
exported. For example:

     >>> ba.append(97)
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
     BufferError: Existing exports of data: object cannot be re-sized

     >>> del ba[-1]
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
     BufferError: Existing exports of data: object cannot be re-sized

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to