使用带有 windows dll 函数的 ctypes 时出现类型错误

type error using ctypes with windows dll function

nl5 是一个 windows dll,它包含一个具有以下原型的函数:

int NL5_Open(char* name)

我正在尝试使用以下 Python3 代码打开文件 "opamp_impulse_response":

from ctypes import cdll, c_int, c_char_p, c_double

nl5_lib = "C:/Users/andre/OneDrive/Desktop/nl5/nl5_dll/nl5_dll_64"
nl5 = cdll.LoadLibrary(nl5_lib)

nl5.NL5_Open.argtypes = [c_char_p] 
nl5.NL5_Open.restype = c_int
oa_file = "C:/User/andre/OneDrive/Desktop/nl5/opamp_impulse_response" 
ncir = nl5.NL5_Open(oa_file) 
ncir

我收到以下错误:

ArgumentError                             Traceback (most recent call last)
<ipython-input-4-d82b34e88c87> in <module>
      2 nl5.NL5_Open.restype = c_int
      3 oa_file = "C:/User/andre/OneDrive/Desktop/nl5/opamp_impulse_response"
----> 4 ncir = nl5.NL5_Open(oa_file)
      5 ncir

ArgumentError: argument 1: <class 'TypeError'>: wrong type

你能告诉我什么是类型错误吗?

在 Python 3 中,'string' 是一个 Unicode 字符串,ctypes 将其转换为 c_wchar_p(wchar_t* 在 C 中)。

对对应于 c_char_p(C 中的 char*)的字节字符串使用 b'string'