我遇到了ctypes的问题.我认为我的类型转换是正确的,错误对我没有意义."arg - ct.c_char_p(logfilepath)"行错误TypeError:预期的字节或整数地址而不是str实例
我试过python 3.5和3.4.
功能我打电话:
stream_initialize('stream_log.txt')
Run Code Online (Sandbox Code Playgroud)
Stream_initialize代码"
def stream_initialize(logfilepath):
f = shim.stream_initialize
arg = ct.c_char_p(logfilepath)
result = f(arg)
if result:
print(find_shim_error(result))
Run Code Online (Sandbox Code Playgroud)
use*_*367 19
c_char_p
接受bytes
对象,所以你必须转换string
为bytes
第一个:
ct.c_char_p(logfilepath.encode('utf-8'))
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是使用c_wchar_p
带有a 的类型string
.