SetWindowsHookEx failing in .NET 4.0 on 32-bit machine with “module not found”?

前端 未结 3 1935
离开以前
离开以前 2020-11-30 07:39

I have found similar questions on this page, but I can\'t seem to figure out how to interpret the answers or figure out if they are truly duplicates.

Here are the pos

3条回答
  •  野性不改
    2020-11-30 08:28

    Yup, I think you understand what's going on. SetWindowsHookEx() requires a valid module handle, and verifies it, but it doesn't actually use it when you set a low-level hook. You just need a valid handle, it doesn't matter which specific one. Calling LoadLibrary("user32.dll") is a good way to get a handle, that DLL will always be loaded anyway since you P/Invoke its methods. And it is always loaded by the CLR bootstrapper (mscoree.dll). Don't bother calling FreeLibrary(), it makes no difference.

    Later versions of Windows no longer perform this check. Not exactly sure when that started, somewhere around Windows 7 SP1 I think. Probably meant to be helpful but invokes the "works on my machine, not the customer's" failure scenario.

提交回复
热议问题