gpt4 book ai didi

Python ctypes addressof CFuncType

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:43 25 4
gpt4 key购买 nike

关于我的other question

如何获取 CFuncType 对象的地址(实际函数指针)? addressof() 没有报告正确的地址。

C 代码:

extern "C" _declspec(dllexport)
int addr(int (*func)())
{
int r = (int)func;
return r;
}

Python代码:

def test():
return 42

t = CFUNCTYPE(c_int)
f = t(test)

print addressof(f)
print dll.addr(f)

输出:

7030864
3411932

尝试从 C 调用 *(7030864) 会导致崩溃,但调用 *(3411932) 会按预期工作。 addressof() 有什么问题?

最佳答案

cast(f, c_void_p) 从 python 中获取正确的地址

关于Python ctypes addressof CFuncType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038839/

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