Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个字符串:
msg="hello world"
如何将其定义为ctypes.c_void_p()数据类型?
ctypes.c_void_p()
以下代码产生“无法转换为指针”异常:
data=ctypes.c_void_p(msg)
data必须是void*C 中的类型,因为它被传递给 DLL。
data
void*
我假设有一种方法可以使用包来打包/解包字符串struct,但不幸的是我对这个过程非常不熟悉。
struct
像这样的东西?使用ctypes.cast?
ctypes.cast
>>> import ctypes >>> p1= ctypes.c_char_p("hi mom") >>> ctypes.cast( p1, ctypes.c_void_p ) c_void_p(11133300)