Python ctypes CFofType的地址 [英] Python ctypes addressof CFuncType
本文介绍了Python ctypes CFofType的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与我的其他问题
如何获取CFuncType对象的地址(虚拟函数指针)?addressof()没有报告正确的地址.
How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address.
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()有什么问题?
trying to call *(7030864) from C causes a crash, but calling *(3411932) works as expected. What's wrong with addressof()?
推荐答案
cast(f,c_void_p)
从python内部获取正确的地址
cast(f, c_void_p)
gets the correct address from within python
这篇关于Python ctypes CFofType的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文