views:

100

answers:

2
+2  Q: 

Module not found

Hi There!

I've been working on this one quite a bit and haven't gotten any closer to a solution.

I juut dug up my old copy of the WindowsHookLib again - It's available with source at http://www.codeproject.com/KB/DLL/WindowsHookLib.aspx. This library allows Global Windows Mouse/Keyboard/Clipboard Hooks, which is very useful.

I'm trying to use the Mouse Hook in here to Capture Mouse-Motion (I could use a Timer that always polls Cursor.Position, but I plan on using more features of WindowsHookLib later).

Code as follows:

MouseHook mh = new MouseHook();
mh.InstallHook();
mh.MouseMove += new EventHandler<WindowsHookLib.MouseEventArgs>(mh_MouseMove);

But on the call to InstallHook(), I get an Exception: "The specified Module could not be found". Strange. Searching, I found that someone thought this occurs because a DLL is not in a place included in the Windows PATH variable, and because placing it in system32 didn't help I went the whole hog and translated the thing to C# for inclusion directly in my project (I was curious how it works).

However the error was obstinately persistent, so I dug a bit on this, and found the Code in the Library that is responsible: In InstallHook(), we have

IntPtr hinstDLL = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
this._hMouseHook = UnsafeNativeMethods.SetWindowsHookEx(14, this._mouseProc, hinstDLL, 0);
if (this._hMouseHook == IntPtr.Zero)
{
      throw new MouseHookException(new Win32Exception(Marshal.GetLastWin32Error()).Message);
}

And this (after modification and recompile) tells me that what I'm really getting is a Windows error "ERROR_MOD_NOT_FOUND"! Now, Here I'm stumped. Didn't I just compile the Hook Library directly into my project?

(UnsafeMethods.SetWindowsHookEx is just a DllImported Method from user32)

Any Answers, or Prods in the right direction, or any hints, pointers or similar are very much appreciated!

A: 

I too am having this problem.

Dylan Vester
A: 

I am also having this problem. I found that it seems to be to do with the version of .Net you are using. .Net 4 you get this error, change to .Net 3.5 and it works.

jpb