c++ - Python passing char * as an argument to a function -
i have created python module c++ static library using cython add-on. c++ library provides function listing contents of folder. provides name of directory contents displayed, output buffer contents of directory stored, , of course length of output buffer. c++ definition of function follows:
int listitems(char *dir, char *buf, int buflen)
the python module in turn has function pylistitems
calls function:
def pylistitems(char *dir, char *buf, int buflen): return listitems(dir,buf,buflen)`
in script using function, define string buffer , pointer of type c_char_p
, , pass function in place of buf
argument:
buf = c_types.create_string_buffer(100) pbuf = c_char_p(addressof(buf)) pylistitems('somefolder',pbuf,100)
but getting following error:
typeerror: expected string or unicode object, c_char_p found
any appreciated.
pbuf = c_char_p(addressof(buf))
you don't need this. create_string_buffer
returns character array. do:
buf = c_types.create_string_buffer(100) pylistitems('somefolder',buf,100)
Comments
Post a Comment