PInvoke errors calling external SetWindowsHookEx and GetModuleHandle

ぃ、小莉子 提交于 2019-12-06 07:43:44

You can't use GetModuleHandle for an external process. It must be a module that has been loaded into the current process.

I had the same issue: 126 = The specified module could not be found. I added missing message loop into my app and it start working again.

I'm using Hook func like this:

 hKeyboardHook = SetWindowsHookEx(
                    WH_KEYBOARD_LL,
                    KeyboardHookProcedure,
                    Marshal.GetHINSTANCE(typeof(your_class_type).Module),
                    0);

and I added Application.Run() at tne end of the Main func

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!