can not add (global) event handler - The specified module could not be found - Error Code : 126

Hello,
I want to add KeyPress Event to my program ;


            this.globalEventProvider1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.globalEventProvider1_MouseDown);

            this.globalEventProvider1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.globalEventProvider1_MouseUp);


when i execute them, I am facing error;

System.ComponentModel.Win32Exception: 'The specified module could not be found'

Solution : We should load user32.dll and make a call as seen below:

Load user32.dll and user it in SetWindowHookEx

 //See comment of this field. To avoid GC to clean it up.
                s_MouseDelegate = MouseHookProc;
                var mar = LoadLibrary("user32.dll");
                //install hook
                s_MouseHookHandle = SetWindowsHookEx(
                    WH_MOUSE_LL,
                    s_MouseDelegate,
                    /* Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), */
                    /* use below instead */
                    mar,
                    0);

good luck.

Comments

Popular posts from this blog

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in CrmServiceHelper.cv

Exception caught instantiating TERADATA report server extension SQL Reporting Services

you face "ISV code aborted the operation" when you change status of the any record in Dynamics CRM 2013