C++ method that cannot be converted from void to LRESULT

  • 2020-04-01 23:36:36
  • OfStack

This should be an MFC program, ON_MESSAGE is the add message response function, this is the add hotkey WM_HOTKEY response function. When you register the hotkey, when the user presses the hotkey, the OnHotKey function is executed to process the message. The error should be the declaration of the OnHotKey function, the return value should be lresult.vs2008 to check the message more strictly, the message map previously fully functioning under VC6 did not compile under VS2008

ON_MESSAGE (WM_message, OnMyMessage);
The return value of OnMessage must be LRESULT, in the form of: afx_msg LRESULT OnMessage (WPARAM, LPARAM);
If not, error C2440: "static_cast" : cannot be converted from "void (s) call CMainFrame: : *)" to "LRESULT (s) call CWnd: : *) (WPARAM, LPARAM)"

The solution is as follows: first, change the return value type of the original message function to LRESULT. Then the parameters of the message function must be rewritten as (WPARAM WPARAM, LPARAM LPARAM) regardless of these two.

Related articles: