简体   繁体   中英

Can we hook function calls in MFC?

I am on a very old MFC application and a lot of callbacks for GUI defined as follows which are spread across 100's of cpp files across different views/documents

ON_COMMAND(ID_FILE_OP1, OnFileOp1)

ON_UPDATE_COMMAND_UI(ID_FILE_OP1, OnUpdateFileOp1)

ON_COMMAND(ID_FILE_OP2, OnFileOp2)

ON_UPDATE_COMMAND_UI(ID_FILE_OP2, OnUpdateFileOp2)

A new requirement requires me to call a function after and before every ON_UPDATE_COMMAND_UI 's defined call back function call and ON_COMMAND as well.

I am trying to create a #define so that a change is localised and works as a hooking mechanism for the call back begin end maybe.

I can definitely call my common function after and before each function call but I don't think that as a clean approach.

Whats the standard or a good approach for this?

I wish to hook to ON_COMMAND & ON_UPDATE_COMMAND_UI call back functions cleanly from outside.

I am on Windows, Visual Studio 2015 x64.

You can install a hook procedure by calling the SetWindowsHookEx function... To retrieve a handle to the DLL module, call the LoadLibrary function with the... wParam, szMsg, c++); if (FAILED(hResult)) { // TODO: writer error...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM