使用带有Windows dll函数的ctypes键入错误

时间:2019-11-10 02:16:54

标签: ctypes

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

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

1 个答案:

答案 0 :(得分:1)

在Python 3中,import { MuiThemeProvider, ServerStyleSheets } from '@material-ui/core/styles' const sheets = new ServerStyleSheets() const components = ReactDOMServer.renderToStaticMarkup( <StaticRouter location={ctx.request.url} context={routeContext}> <Provider store={ctx.store}> <IntlProvider> {sheets.collect( <MuiThemeProvider theme={theme}> <Application history={history} /> </MuiThemeProvider> )} </IntlProvider> </Provider> </StaticRouter> ) 是一个Unicode字符串,ctypes将其转换为'string'(C语言中的wchar_t *)。

c_wchar_p用于与b'string'(C中的char *)相对应的字节串。