Python 在ctypes中传递文件路径的正确方法是什么

Python 在ctypes中传递文件路径的正确方法是什么,python,python-2.7,ctypes,dllexport,Python,Python 2.7,Ctypes,Dllexport,我有带有函数(char*filename,int-run)的dll驱动程序。我是从Python2.7调用的,ctypes如下 import ctypes as ct mydll = ct.cdll.LoadLibrary(dll_file_path) function = mydll.function function.argtypes=(ct.POINTER(ct.c_char_p),ct.c_int) function.restype=ct.c_int filename=b'C:\\Us

我有带有
函数(char*filename,int-run)的dll驱动程序
。我是从Python2.7调用的,ctypes如下

import ctypes as ct
mydll = ct.cdll.LoadLibrary(dll_file_path)
function = mydll.function
function.argtypes=(ct.POINTER(ct.c_char_p),ct.c_int)
function.restype=ct.c_int


filename=b'C:\\Users\\data.dat'

function(ct.c_char_p(filename),100)

我在网上阅读,有人说最好使用
ct.create\u string\u buffer
。我不知道如何使用它。我使用
ct.POINTER(ct.c\u char\u p)
时出错。我的问题是,在ctypes中传递文件路径/名称的正确方法是什么?如果
ct.create\u string\u buffer
是正确的方法,我应该如何更改
function.argtypes

C字符串是以null结尾的
char
数组,通常作为char指针传递,即
char*
。在ctypes中,这最好用
c\u char\p
来表示,尽管有时您可能需要
指针(c\u char)
。但是
指针(c\u char\u p)
是一个c
char**
,在本例中,您肯定不需要它。c字符串是一个以null结尾的
char
数组,通常作为char指针传递,即
char*
。在ctypes中,这最好用
c\u char\p
来表示,尽管有时您可能需要
指针(c\u char)
。但是
指针(c\u char\u p)
是一个c
char**
,在这种情况下,您肯定不希望使用它。