How do I use ctypes to set a library's extern function pointer to a Python callback function?

This is tricky in ctypes because ctypes function pointers do not implement the value property used to set other pointers. Instead, cast your callback function and the extern function pointer to void with the c_void_p function. After setting the function pointer as void as shown, C can call your Python function, and you can retrieve the function as a function pointer and call it with normal ctypes calls.

This is tricky in ctypes because ctypes function pointers do not implement the . Value property used to set other pointers. Instead, cast your callback function and the extern function pointer to void * with the c_void_p function.

After setting the function pointer as void * as shown, C can call your Python function, and you can retrieve the function as a function pointer and call it with normal ctypes calls. From ctypes import * liblibrary = cdll. LoadLibrary('liblibrary.So') def py_library_hook(strings, n): return 0 # First argument to CFUNCTYPE is the return type: LIBRARY_HOOK_FUNC = CFUNCTYPE(c_int, POINTER(c_char_p), c_int) hook = LIBRARY_HOOK_FUNC(py_library_Hook) ptr = c_void_p.

In_dll(liblibrary, 'library_hook') ptr. Value = cast(hook, c_void_p).value.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions