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 possible duplicates I've found, with comments:
SetWindowsHookEx returns 0 when compiling for the .NET 4.0 framework in 32bit machines
It doesn't seem to return 0 on mine, but I noticed that the handle reported when it crashes (.NET 4.0 on 32-bit) is way different from the handle reported when it runs (.NET 3.5 on 32-bit), like crash handle = 523727, and working handle = 172738378.
Calling SetWindowsHookEx inside VS2008 debugger always returns NULL
I can repro my problem when running outside of Visual Studio
-
This seems most promising, except that the comments to the deleted answer mentions I should use LoadLibrary and GetProcAddress to load user32.dll in .NET 4.0 since something about loading assemblies changed. I'm pretty sure, however, that it is my own module it can't find, but I don't know if this applies.
The comments in question on the deleted answer to that last one, by Hans Passant, reads:
Are you using .NET 4.0? Its CLR changed the way assemblies are loaded, there is no longer a LoadLibrary call, there won't be module handle for them. Using GetEntryAssembly() instead would be another fix. – Hans Passant May 5 at 19:43
So, what's the word here? Are you using .NET 4.0? Did you try using LoadLibrary("user32.dll") to get a usable DLL handle? – Hans Passant May 6 at 15:43
I'm pretty sure I don't nee