+ -
当前位置:首页 → 问答吧 → python调用c函数时返回含Null的char*

python调用c函数时返回含Null的char*

时间:2011-09-30

来源:互联网

如题
某c++函数 返回char*
内容为"Hello\x00World!!!"
已知长度
python如何接受?
ctypes,swig都直接映射成以NULL结尾的字符串(这个设计真不爽)

作者: asd2314asd   发布时间: 2011-09-30

你的ctypes代码怎么写的?贴出来看下。

作者: iambic   发布时间: 2011-09-30

size=ctypes.c_int(14)
str=ctypes.c_char_p(""Hello\x00World!!!"")
dll=ctypes.CDLL("pix.dll")
dll.rt.restype = ctypes.c_char_p
dll.rt.argtypes=[ctypes.c_char_p,c_int]
newstr=ctypes.c_char_p(dll.rt(str,size)).value
我只是举个例子
贴出来有什么用吗?

作者: asd2314asd   发布时间: 2011-09-30