I came up with an ATL-style class (with some map macros) and thought I'd submit it here. It's for setting WinEvent hooks. My rough draft looks like this, but maybe you can improve it:
Well perhaps this can be accomplished without that object. But I think you need a way of accessing specific class instances within the static WinEventProc. The only thing WinEventProc gives you is hWinEventHook. So I just figured I'd create a map of hook handles to object pointers. But there's probably a better way. This ATL and Winapi stuff ties my brain in knots.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Bill,
It seems the ATL thunking class CStdCallThunk (not CWndProcThunk) can be used in this case too. Have you already looked into this?
You may then have say, CWinEventHookRoot with the thunking and CWinEventHookImpl providing the non-static procedure, no virtual method.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't really gotten into thunking yet. I'm pretty new to WinAPI and ATL. So I'd defer to you and other people on that.
On another note, maybe it would be more useful to create a CUIAutomationEventHandlerImpl instead. UIAutomation is probably better than SetWinEventHook overall, and it wouldn't involve the static callback issues. But it would present challenges of its own in creating the map macros.
Last edit: Bill Stevens 2021-05-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I came up with an ATL-style class (with some map macros) and thought I'd submit it here. It's for setting WinEvent hooks. My rough draft looks like this, but maybe you can improve it:
Thanks for any feedback.
Last edit: Bill Stevens 2021-03-11
Hello Bill,
Looking good but what is the real use of the
s_mapHooksToObjPtrs
object?Well perhaps this can be accomplished without that object. But I think you need a way of accessing specific class instances within the static WinEventProc. The only thing WinEventProc gives you is hWinEventHook. So I just figured I'd create a map of hook handles to object pointers. But there's probably a better way. This ATL and Winapi stuff ties my brain in knots.
There's no way that's clearly better. See:
https://github.com/microsoft/Windows-Dev-Performance/issues/28
Hello Bill,
It seems the ATL thunking class
CStdCallThunk
(notCWndProcThunk
) can be used in this case too. Have you already looked into this?You may then have say,
CWinEventHookRoot
with the thunking andCWinEventHookImpl
providing the non-static procedure, no virtual method.I haven't really gotten into thunking yet. I'm pretty new to WinAPI and ATL. So I'd defer to you and other people on that.
On another note, maybe it would be more useful to create a
CUIAutomationEventHandlerImpl
instead. UIAutomation is probably better than SetWinEventHook overall, and it wouldn't involve the static callback issues. But it would present challenges of its own in creating the map macros.Last edit: Bill Stevens 2021-05-16