Pass A Function Pointer From A C Dll To A C Dll
I am trying to use the Windows function: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa to register a global hook. I have created a hook pr
Solution 1:
I got the callback working and the hook registered with the following code:
# Set callback from windows hook procedure to our python code
dll_name = "FSHooks.dll"
dll_abspath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'Win32',
'Debug', dll_name))
dll_handle = cdll.LoadLibrary(dll_abspath)
self.callback_type = CFUNCTYPE(None, c_int, c_int, c_int, c_bool)
self.callback = self.callback_type(self.callback_from_c)
dll_handle.Init()
dll_handle.SetCallback(self.callback)
# TODO - Release the hooks when window closes# Register the hook
dll_handle.HookProc.argtypes = (c_int, wintypes.WPARAM, wintypes.LPARAM)
hook_proc_pointer = dll_handle.HookProc
self.hook_id = windll.user32.SetWindowsHookExA(win32con.WH_MOUSE_LL, hook_proc_pointer,
win32api.GetModuleHandle(None), 0)
It appears you can just take the attribute that is the name of the function in the dll and it accepts it as a pointer argument. I had to set the argument types and it worked.
Post a Comment for "Pass A Function Pointer From A C Dll To A C Dll"