gpt4 book ai didi

python - 如何将 ctypes c_void_p 对象转换为实际类型?

转载 作者:太空宇宙 更新时间:2023-11-04 06:09:02 24 4
gpt4 key购买 nike

我有一个使用 ctypes 的 C 库包装函数,看起来像这样

rrpLib.getParameterValueAsPointer.restype = c_void_p
def getParameterValueAsPointer(parHandle):
return rrpLib.getParameterValueAsPointer(parHandle)

其中 rrpLib 是 ctypes CDLL 对象。对于某个 parHandle,底层对象是已知的 double*。

如何转换 c_void_p 对象以便在 python 端获得实际的双数?

最佳答案

解决这个问题,感谢 eryksun 的建议。正确的方法似乎是做

my_void_val = getParameterValueAsPointer(aParaHandle)
my_dbl_ptr = cast(my_void_val , POINTER(c_double))
print(my_dbl_ptr[0])

给出正确的值。

关于python - 如何将 ctypes c_void_p 对象转换为实际类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19992644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com