COMMAND AND UPDATE_COMMAND_UI handlers not called

2019-08-10 06:32发布

问题:

I have ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for menu items in an MFC dll. But they are not invoked. The same code compiled as .exe has the handlers being invoked. What could be the reason for this?

回答1:

ON_UPDATE_COMMAND_UI and ON_COMMAND handler are only called when the object that contains the handler is within the command routing.

So the DLL itself isn't the problem but also this depends on how you created your DLL. For a standard DLL and without sharing the MFC as a DLL this will not work at all. AFAIK to get it run the DLL should be an extension DLL loaded into the application. The reason is that the main application wil not recognize your objects in a standard DLL when the MFC is statically linked.

Read more about command routing in the MSDN and in the technical notes



标签: c++ dll mfc