python: how to cast a list to c_byte array
Question: I have a c function in dll.

It has a interface like `int dcm(char inmsg[], int length);`

Now I have a list like(the number of member are more than 1000 sometimes)

    
    
    a = [0x41,0x00,0x00,0xC8,0x08,0x01,0x03,0x00,0x00,0x02,0x10,0x00,0x66,0x62,0x05,0x00,0x06,0x00,0x57,0x02,0x01,0xBF,0xFF,0x00,0xBF,0x9A,0x00,0x05,0x80,0x10,0x32,0x00,0x07,0x1F,0x00,0x00,0x05,0x00,0xD1,0x01,0x01,0xBF,0x04,0x00,0x03,0xBF,0x04,0x00,0x21,0x64,0x00,0x00,0x0A,0xBF,0xFF,0x00,0xBF,0xFF,0x00,0xBF,0xFF,0x00,0xBF,0xF3,0x00]
    

I want to cast the list to `c_byte` array and pass it as the first parameter
for the function `dcm`.

How to cast it to c_byte array?


Answer: You can do this -

    
    
    import ctypes
    a = [0x41,0x00,0x00,0xC8,0x08,0x01,0x03,0x00,0x00,0x02,0x10,0x00,0x66,0x62,0x05,0x00,0x06,0x00,0x57,0x02,0x01,0xBF,0xFF,0x00,0xBF,0x9A,0x00,0x05,0x80,0x10,0x32,0x00,0x07,0x1F,0x00,0x00,0x05,0x00,0xD1,0x01,0x01,0xBF,0x04,0x00,0x03,0xBF,0x04,0x00,0x21,0x64,0x00,0x00,0x0A,0xBF,0xFF,0x00,0xBF,0xFF,0x00,0xBF,0xFF,0x00,0xBF,0xF3,0x00]
    arr = (ctypes.c_byte * len(a))(*a)
    

Then you can pass `arr` to your C function. More details are [in the
doc](http://docs.python.org/2/library/ctypes.html#arrays).

