I'm accessing one function from dll which need file pointer (char *filename). How can I pass it through python?
handle = cdll.dsp
p = open("signal.txt", "r")
handle.filter(p)
A file pointer is FILE *
. But you mentioned you need char *filename
, which is a char pointer (ie a null-terminated string). I'm going to assume the C function has a prototype void filter(char *filename)
.
First you must define the function argument types and the return type :
import ctypes
filter = ctypes.cdll.dsp.filter
filter.argtypes = (ctypes.c_char_p,)
filter.restype = None # Or whatever type it returns.
Then you call it:
filter("signal.txt")
By the way, you tagged your question as Python 2.7, but nowadays you should move on to Python 3, unless you have a really good reason to stay at the older version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.