Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
Hi,
I am doing wpf project in which i have do multiple activities at same time so i use background worker process for each activity. i use class library. and also uses code

C#
ActivityManager.MouseMove  += HookManager_MouseMove;
          ActivityManager.MouseClick += HookManager_MouseClick;
          ActivityManager.MouseUp += HookManager_MouseUp;
          ActivityManager.MouseDown += HookManager_MouseDown;

which gives me Error code 126:The specified module could not be found.


ActivityManager is a class as follows:
C#
public static class ActivityManager
    {
        public static event KeyEventHandler KeyDown;
        public static event KeyPressEventHandler KeyPress;
        public static event KeyEventHandler KeyUp;
        public static event MouseEventHandler MouseClick;
        public static event EventHandler<MouseEventExtArgs> MouseClickExt;
        public static event MouseEventHandler MouseDoubleClick;
        public static event MouseEventHandler MouseDown;
        public static event MouseEventHandler MouseMove;
        public static event EventHandler<MouseEventExtArgs> MouseMoveExt;
        public static event MouseEventHandler MouseUp;
        public static event MouseEventHandler MouseWheel;
}

Although, i have added all the references and intellisense working i still get "Error :126" i.e The specified module could not be found.

HookManager_MouseMove is a event which i specify at runetime for handling MouseMove event.
Posted
Updated 5-Jun-14 19:10pm
v2
Comments
[no name] 5-Jun-14 8:22am    
Please show the code that produces that error.
sachin Bhosale @ code 6-Jun-14 4:50am    
private static void EnsureSubscribedToGlobalKeyboardEvents()
{
// install Keyboard hook only if it is not installed and must be installed
if (s_KeyboardHookHandle == 0)
{
//See comment of this field. To avoid GC to clean it up.
s_KeyboardDelegate = KeyboardHookProc;
//install hook
s_KeyboardHookHandle = SetWindowsHookEx(
WH_KEYBOARD_LL,
s_KeyboardDelegate,
Marshal.GetHINSTANCE(
Assembly.GetExecutingAssembly().GetModules()[0]),
0);
//If SetWindowsHookEx fails.
if (s_KeyboardHookHandle == 0)
{
//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
int errorCode = Marshal.GetLastWin32Error();
//do cleanup

//Initializes and throws a new instance of the Win32Exception class with the specified error.
throw new Win32Exception(errorCode);
}
}
}
[no name] 5-Jun-14 23:24pm    
Please be more specific. What you wrote is not enough.
sachin Bhosale @ code 6-Jun-14 4:53am    
I am using class library specified in at:

http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C

and
code
if (s_KeyboardHookHandle == 0)
{
//See comment of this field. To avoid GC to clean it up.
s_KeyboardDelegate = KeyboardHookProc;
//install hook
s_KeyboardHookHandle = SetWindowsHookEx(
WH_KEYBOARD_LL,
s_KeyboardDelegate,
Marshal.GetHINSTANCE(
Assembly.GetExecutingAssembly().GetModules()[0]),
0);

gives me error 126
sachin Bhosale @ code 6-Jun-14 4:54am    
I am using HookManager to monitor activities of Keyboard and mouse in Async Mode as register event handler in background worker process but , i am getting error 126 i.e Specified module is not Found.Does it work in Async Mode?

1 solution

Replace it with

VB
s_KeyboardHookHandle = SetWindowsHookEx(
                    WH_KEYBOARD_LL,
                    s_KeyboardDelegate,
                        IntPtr.Zero,
                            0);



or try this

A Simple C# Global Low Level Keyboard Hook[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900