开发者

Python ctypes addressof CFuncType

开发者 https://www.devze.com 2022-12-16 03:21 出处:网络
Related to my other question How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address.

Related to my other question

How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address.

C code:

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

Python code:

def test():
  return 42

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

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

Output:

7030864
3411932

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) gets the correct address from within python

0

精彩评论

暂无评论...
验证码 换一张
取 消