There is no function with this name in the range of matching target type. error C2440 “static_cast” cannot be converted from “void (__thiscall C*)

 error C2440: "static_cast": not from the "void (__thiscall CDataStatistics :: *) (CMenu *, UINT, bool)" is converted to "void (__thiscall CWnd :: *) (CMenu *, UINT, BOOL)"
  developed by the platform When VC6.0 is upgraded to a version above VS2005, the original project needs to be migrated, and similar errors may be encountered:

error C2440: "static_cast" cannot be used from "void (__thiscall C* )(void)...

Versions after VS2005 have stricter message checking. The message mapping that was completely normal under VC6 compiles under VS2005 does not pass
OnMyMessage. The return value must be LRESULT, in the form: afx_msg LRESULT OnMyMessage(WPARAM, LPARAM); if not If yes, there will be an error message: the
solution is as follows:

First, change the return value type of the original message function to LRESULT, and you can write a return TRUE in the function; 

Then the parameters of the message function must be rewritten as (WPARAM wParam, LPARAM lParam) regardless of whether these two parameters are used or not;

Finally, the message mapping such as ON_MESSAGE (WM_message, & OnMyMessage).

 

In the header file:

afx_msg LRESULT OnOnRobotInit(WPARAM wParam,LPARAM lParam);
    afx_msg LRESULT OnOtherPartInit(WPARAM wParam,LPARAM lParam);

 

In the cpp file:
BEGIN_MESSAGE_MAP(CInitDeviceDlg, CDialog)

//{ {AFX_MSG_MAP(CInitDeviceDlg)
    //ON_BN_CLICKED(IDC_BUTTON1, OnOnRobotInit)//-------------ttttt
    ON_MESSAGE(IDC_BUTTON1, OnOnRobotInit)                 //改成这样
    //ON_BN_CLICKED(IDC_BUTTON2, OnOtherPartInit)//---------------ttttt
    ON_MESSAGE(IDC_BUTTON2, OnOtherPartInit)            //改成这样
    ON_WM_CLOSE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//int CInitDeviceDlg::OnOnRobotInit() 

//
LRESULT CInitDeviceDlg::OnOnRobotInit(WPARAM wParam,LPARAM lParam) in the  function body

{

}

Guess you like

Origin blog.csdn.net/txwtech/article/details/105418740