web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dynamics of Things / can not add (global) event ...

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

Muhammet ATALAY Profile Picture Muhammet ATALAY 60
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.


This was originally posted here.

Comments

*This post is locked for comments