【发布时间】:2018-12-02 00:30:49
【问题描述】:
我在使用 ctypes 调用应该返回字符串的 C++ 库(用 extern C 包装)中的函数时遇到问题。我很确定我已经为 ctypes 接口正确设置了我的 argtypes 和 restype 到一个应该返回字符串的函数中,但无论如何我只会得到一个空字符串作为返回的结果。
C++ 代码:
const char* disasmC_PEProgram_getSections(PEProgram *p) {
return p->getSections().c_str();
}
Python 代码:
lib.disasmC_PEProgram_getSections.argtypes = [ctypes.c_void_p]
lib.disasmC_PEProgram_getSections.restype = ctypes.c_char_p
resultStr = lib.disasmC_PEProgram_getSections(self.peProgram_p)
# Displays empty string for resultStr!
print "Result: %s" % (resultStr,)
【问题讨论】:
-
打印结果:%s" % (resultStr.value)?