轉自:http://blog.csdn.net/chenyujing1234/article/details/7387712
不能轉換void (_thiscall CMainFrame::*)(void)to LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)2010-05-13 11:35開發平台由VC6.0升級至VS2005,需要將原有的項目遷移,可能碰到類似錯誤: error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' VS2005對訊息的檢查更為嚴格,以前在VC6下完全正常啟動並執行訊息映射在VS2005下編譯不通過 ON_MESSAGE(WM_message,OnMyMessage); OnMyMessage傳回值必須為LRESULT,其形式為:afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);如果不符合,則有錯誤提示: error C2440: “static_cast”: 無法從“void (__thiscall CPppView::* )(WPARAM,LPARAM)”轉換為“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)” 在匹配目標類型的範圍內沒有具有該名稱的函數 error C2440: “static_cast”: 無法從“void (__thiscall CPppView::* )(void)”轉換為“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)” 在匹配目標類型的範圍內沒有具有該名稱的函數
解決方案如下: 首先,把原來的訊息函數傳回值類型改為LRESULT,函數內可以隨便寫個return TRUE; 然後訊息函數的參數必須改寫成(WPARAM wParam,LPARAM lParam)而不論這兩個參數是否用得到;最後,訊息映射如ON_MESSAGE(WM_message,& OnMyMessage)