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

Assembly Microsoft.Dynamics.Service.Plugins.dll can not be loaded. Dynamics CRM 365 Engine version 9 - CRM User creation error

Exception caught instantiating TERADATA report server extension SQL Reporting Services

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