Difficulty implementing SetWindowsHookEx
#248
-
Actual behaviorApologies if I'm misunderstanding something, documentation is rather sparse. I'm attempting to implement a low level keyboard hook in a .net 5.0 console (for now) app. Translating from a simple C++ example:
To C#: class Program
Attempting to use I've seen a few more involved examples than this, and some where just I believe this is related to microsoft/win32metadata#147 but couldn't find a workaround in the thread. What is the correct way to go about this? Expected behaviorA way to use GetModuleHandle in SetWindowsHookEx, or a working alternative. Repro steps
Context
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Cant you pass in Also why use |
Beta Was this translation helpful? Give feedback.
-
Passing in null without casting is ambiguous.
Most of this is pretty new to me, I've fiddled with this stuff a little via Power Toys, mostly I just want to get the hook set up and then code away as normal in C#. I attempted briefly writing a basic SafeHandle that would just return false for
|
Beta Was this translation helpful? Give feedback.
-
Your problem may not be the interop at all. Maybe it's because the way the callback is invoked is via the Windows message pump, and your console app doesn't have one. |
Beta Was this translation helpful? Give feedback.
Your problem may not be the interop at all. Maybe it's because the way the callback is invoked is via the Windows message pump, and your console app doesn't have one.