Message Passing MFC error C2440 "static_cast" cannot convert from "void (_thiscall) (void)" to "LRESULT

Source: Internet
Author: User

Reprint to: http://www.educity.cn/wenda/566627.html

Error C2440 "static_cast" cannot convert from "void (__thiscall) (void)" to "LRESULT
Error C2440

"Static_cast" cannot convert from "void (__thiscall Cpppview) (void)" to "LRESULT (__thiscall CWnd) (Wparam,lparam)"

Cannot convert void (_thiscall CMainFrame::*) (void) to LRESULT (__thiscall CWnd::*) (Wparam,lparam) The development platform is upgraded from VC6.0 to VS2005, and the original project needs to be migrated.

You may encounter a similar error:
Error C2440: ' static_cast ': cannot convert from ' void (__thiscall CMainFrame::*)

(void) ' to ' LRESULT (__thiscall CWnd::*) (Wparam,lparam) '

VS2005 the message is more stringent, the message map that was previously fully operational under VC6 is not compiled under VS2005

On_message (Wm_message,onmymessage);
The OnMyMessage return value must be LRESULT in the form: afx_msg LRESULT onmymessage (WPARAM, LPARAM), and if not, there is an error message:
Error C2440: "static_cast": Cannot convert from "void (__thiscall Cpppview::*) (Wparam,lparam)" to "LRESULT (__thiscall CWnd::*) (WPARAM, LPARAM) "Does not have a function with that name in the range that matches the target type
Error C2440: "static_cast": Cannot convert from "void (__thiscall Cpppview::*) (void)" to "LRESULT (__thiscall CWnd::*) (Wparam,lparam)" in There is no function with that name in the range that matches the target type



Here's how to fix it:

For example: TransparentWnd.cpp in On_message (wm_liben,onliben):

First: Change the original message function return value type to LRESULT (find Onliben definition, such as Viod Ctransparentwnd::onliben (WPARAM wparam,lparam LPARAM) to Lresult Ctransparentwnd::onliben (WPARAM wparam,lparam LPARAM), the declaration office will also be changed, such as Afx_msg LRESULT Onliben (WPARAM wparam,lparam LPARAM);) ;

Second: The function can be written in a random return TRUE;

Third: Then the parameters of the message function must be rewritten (WPARAM Wparam,lparam LPARAM) Regardless of whether the two parameters are used;

IV: Message maps such as On_message (wm_message,& onmymessage)

Message Passing MFC error C2440 "static_cast" cannot convert from "void (_thiscall) (void)" to "LRESULT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.