pointers - set c_char_p in Python -
in c header file have:
long test_api callandsave( ___out_ char param1[31], ___out_ char param2[5], ___out_ char param3[21], ___out_ char* pointerparam );
i trying set , pass parameters in python
, pass them callandsave
:
import ctypes ctypes import * lib = cdll.loadlibrary('./testlib.so') param1 = (ctypes.c_char*31)() param2 = (ctypes.c_char*5)() param3 = (ctypes.c_char*21)() pointerparam = ctypes.c_char_p() lib.efttrx(param1,param2,param3,pointerparam)
but getting "output parameter null
" error pointerparam
. how should define "___out_ char* pointerparam
" in python correctly?
___out_ char* pointerparam
the ___out_
in specification means pointer have data written it. must allocate buffer write to. ctypes.c_char_p()
doesn't make buffer - it's null pointer.
look ctypes.create_string_buffer
. must figure out how big of buffer callandsave
expects.
Comments
Post a Comment