error C2440: ‘static_cast’ : cannot convert from ‘void (__thiscall CMainFrame::* )

來源:互聯網
上載者:User

轉自: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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.