VC2010——error C2440 “static_cast” 无法从“void (_thiscall )(void)”转换为“LRESULT
来源:互联网 发布:待机长平板 知乎 编辑:程序博客网 时间:2024/06/05 05:58
在孙鑫C教程9,写到添加用户定义了UM_PROGRESS声明OnProgress消息时出错:
“static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall CWnd )(WPARAM,LPARAM)”
原因:
开发平台由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)”在匹配目标类型的范围内没有具有该名称的函数
解决方法如下:
例如:MainFrm.cpp中ON_MESSAGE(UM_PROGRESS,OnProgress):
第一:把原来的消息函数返回值类型改为LRESULT(找到OnProgress定义,如Viod CMainFrame::OnProgress(WPARAM wParam,LPARAM lParam)改成LRESULT CMainFrame::OnProgress(WPARAM wParam,LPARAM lParam),声明处也要改,成如afx_msg LRESULTOnProgress(WPARAM wParam,LPARAM lParam););
第二:函数内可以随便写个return TRUE;
第三:然后消息函数的参数必须改写成(WPARAM wParam,LPARAM lParam)而不论这两个参数是否用得到;
第四:消息映射如ON_MESSAGE(UM_PROGRESS,OnProgress)
第一:把原来的消息函数返回值类型改为LRESULT(找到OnProgress定义,如Viod CMainFrame::OnProgress(WPARAM wParam,LPARAM lParam)改成LRESULT CMainFrame::OnProgress(WPARAM wParam,LPARAM lParam),声明处也要改,成如afx_msg LRESULTOnProgress(WPARAM wParam,LPARAM lParam););
第二:函数内可以随便写个return TRUE;
第三:然后消息函数的参数必须改写成(WPARAM wParam,LPARAM lParam)而不论这两个参数是否用得到;
第四:消息映射如ON_MESSAGE(UM_PROGRESS,OnProgress)
0 0
- VC2010——error C2440 “static_cast” 无法从“void (_thiscall )(void)”转换为“LRESULT
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall CWnd )(WPARAM,LPARAM)”
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__t
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall CWnd )(WPARA
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thisca
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thisca
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall CWnd )(WPARA
- error C2440: “static_cast”: 无法从“void (__thiscall CXXDlg* )(void)”转换为“LRESULT (__thiscall CWnd:的错误
- error C2440: “static_cast” : 无法从“void (__thiscall CMainFrame::* ) (NMTOOLBARA *,LRESULT *)”转换为“void
- vs2008 error C2440: “static_cast”: 无法从“void (__thiscall CMainFrame::* )(void)”转换为“LRESULT (__thiscal
- error C2440: “static_cast”: 无法从“void (__thiscall CTransparentWnd::* )(WPARAM,LPARAM)”转换为“LRESULT (__
- error C2440: “static_cast”: 无法从“void (__thiscall CMyDlg::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscall
- error C2440: “static_cast”: 无法从“void (__thiscall CChatDlg::* )(WPARAM,LPARAM)”转换为“LRESULT
- error C2440: “static_cast”: 无法从“void (__thiscall CChatDlg::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscal
- MyBatis底层基础和拦截器 - 第一部分
- 字符串以XX开头或结尾
- hdu 1540(线段树单点更新 区间合并)
- sort +awk+uniq 统计文件中出现次数最多的前10个单词
- Leetcode 10. Regular Expression Matching
- VC2010——error C2440 “static_cast” 无法从“void (_thiscall )(void)”转换为“LRESULT
- 分享卫星位置速度和轨道计算 MATLAB
- 了解Bootstrap
- 7_Android动画深入分析
- 五猴分桃
- soledede-Item-Based Recommendation(基于项目的系统过滤推荐)
- android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
- 百度的echart环形图颜色动态设置
- 数据库上机实验学习记录最新Day1117