SetWindowsHookEx失败

使用下面代码hook鼠标

 res = SetWindowsHookEx(WH_MOUSE_LL, _mouseHookProcedure, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]), 0); 

 

结果res = 0 ,使用 GetLastError()获得返回值=126  (找不到指定的模块)

 

解决方法,用下面语句替换

var mar = LoadLibraryW("user32.dll");
res = SetWindowsHookEx(WH_MOUSE_LL, _mouseHookProcedure, mar, 0);

 

posted @ 2019-09-12 10:56  quanzhan  阅读(1073)  评论(0编辑  收藏  举报