Python ctypes addressof CFuncType

Related to my other question

How can I get the address (acctual function pointer) for 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

Attempting to call * (7030864) from C fails, but calling * (3411932) works as expected. What is wrong with addressof ()?

+3
source share
1 answer

cast(f, c_void_p) gets the correct address from python

+6
source

Source: https://habr.com/ru/post/1727989/


All Articles