Apparently .NET 3.5, and 64-bit OS+program uses LoadLibrary to load extra assemblies, so they all get a valid module-handle, but a 32-bit IL-only assembly will not, so it gets no such handle
if you're injecting, it makes sense - Windows needs to know what module your callback routine is in, so it can load it into other processes. But for your own process, it's already loaded... All Windows needs to know is the address, and which thread to call it from.
Looking at the documentation on that function, it says:
A handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
My emphasis
For the thread id, if I set it to 0, it is associated with all threads in the same desktop as the calling thread.
So I took that to mean that I have to pass 0 for the thread id, otherwise it would not capture key strokes pressed in other processes, and then I would have to provide a handle
If I pass it as 0 (IntPtr.Zero), I get a "file not found" in a different part of the program, so I'm guessing it hijacks something in a bad manner here
Yep, crashes hard when I press any key after installing the hook, though the installation didn't crash
for a _LL hook, Windows suspends the thread the message is intended for and sends a message to the specified thread in your app that triggers your hook
once you're done processing, it resumes the original thread
(if you take too long, it'll do that anyway... but don't take too long)
Note that passing the module handle and 0 for thread id (ie. global) worked nicely when the assembly was 64-bit, and it was running on 64-bit OS
but apparently it was changed in .NET 4.0 so that not all 32-bit assemblies are loaded using LoadLibrary, and thus won't get a module handle
if I change to .NET 3.5, it runs nicely on both 32-bit and 64-bit, but that's last resort since it means I have to downgrade some class libraries as well
> We made a change in .NET 4 Beta2 where we avoid calling LoadLibrary on IL-only images in 32-bit processes.
Manually loading my assembly that contains the hook code, through LoadLibrary, and passing that handle to SetWindowsHookEx, installs the hook, but then subsequently fails somewhere else with a file not found exception
I'm guessing that it doesn't really manage to get that working, and I didn't think it would either
In any case, I'm off to bed, my head hurts like hell, I'm thinking I'm coming down with an angry cold or something
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 machine...
Appreciate the help @Shog9, if you have any other thoughts, I'll check the transcript tomorrow, and my email address is lasse@vkarlsen.no if you feel so inclined
20 mins sleep schedule? hehe no, but I guess I could sleep for shorter than that and still have a SO answer by "morning" :)
@LasseVKarlsen I don't do a lot of work with managed code, so probably can't help you... but I would check & see if AppDomain.GetCurrentThreadId is actually the thread ID used by WinAPI
> Programmers is a collaboratively edited question and answer site for people who love indirectly relate to programming. It's 100% free, no registration required.
I suggest:
Welcome New User Programmers is a collaboratively edited question and
answer site for people who love
anything which indirectly relates to
programming. It's 100% free, no
registration required
Simple, but effective... :-)
Simply press the Quote button (or hit Ctrl-Q) in any textbox with the Markdown toolbar.
This is what I should get:
>
This is what I get:
Blockquote
Blockquote> BlockquoteBlockquote
Blockquote
If you try selecting some text to blockquote, the same glitch will happen, except each extra ...
When highlighting text and using the quote button, the replaced text is incorrect. It takes the end of the quote, and adds that as extra to both the beginning and the end of the replaced text, messing up the quote. This text is quoted below as an example.
example.
example.> When highlighting ...
Possible Duplicate:
Bug using quote button in Google Chrome on Windows
Since this one is a bit hard to explain, here's a video
http://www.youtube.com/watch?v=LsABVhOmzhc
Chromium build: 6.0.464.0 (52070) Ubuntu 10.04 amd64
Chrome is the best web browser out there, bar none, the best web browser for a software developer is still Firefox -- mainly because Chrome add-ins can only be web pages, so the full richness of FireBug is impossible to achieve in Chrome.
At least not using the current Chrome plugin model.
Well, I would just bump up this question with an edit, but my meta rep isn't high enough. So I'm posting this as a new question.
Here's the problem: in the latest stable version of Google Chrome (6.0.472.53) -- now out of beta -- clicking on the "Blockquote" button in the editor results in a str...
Well, damn, I think my life just went through a mini apocalypse. One server kernel panicked, my father called me to tell me my stepmother's mother is in hospital in grave condition, and I just found out my landlord is filing bankruptcy and I may have to move out of my house -- all within the span of 1.5 hours!