error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTCP服务器程序Dlg::* )(WPARAM,LPARAM)'
来源:互联网 发布:删除列sql语句 编辑:程序博客网 时间:2024/05/30 02:53
在VC6.0下能够运行的代码一由于开发平台的升级可能会导致一些错误的产生,比如今天在进行winsocket编程中在VC6.0下能都运行的代码
自定义消息映射:ON_MESSAGE(WM_SOCKET,OnSocket)
在CTCP服务器Dlg.h中的定义的自定义消息
#define WM_SOCKET WM_USER+100
class CTCP服务器Dlg :public CDialog
{
.... //省略若干代码
protected:
//自定义消息响应函数
afx_msg void OnSocket(WPARAM wParam,LPARAM lParam);
}
void CTCP服务器Dlg::OnSocket(WPARAM wParam,LPARAM lParam)
{
......//省略代码
}
当编译时会产生错误:error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTCP服务器程序Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
在匹配目标类型的范围内没有具有该名称的函数
因为vs2010对消息的检查更为严格,所以虽然上面的代码可以在vc6.0下运行,但是在vs2010下就会出错。
ON_MESSAGE(WM_SOCKET,OnSocket);
OnMyMessage返回值必须为LRESULT,其形式为:afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);如果不符合,则有错误提示:
解决的办法是:
首先,把原来的消息函数返回值类型改为LRESULT,函数内可以随便写个return TRUE; 然后消息函数的参数必须改写成(WPARAM wParam,LPARAM lParam)而不论这两个参数是否用得到;最后,消息映射如ON_MESSAGE(WM_SOCKET,OnSocket)。
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTCP服务器程序Dlg::* )(WPARAM,LPARAM)'
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall MenuToolBar::* )(LPARAM,LRESULT *)' to 'void (__thiscall CCmd
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall MenuToolBar::* )(LPARAM,LRESULT *)' to 'void (__thiscall CCmd
- error C2440 static_cast:cannot convert from void (_thiscall X::*)(WPARAM,LPARAM)to LRESULT(_thiscall
- VS2010 error C2440: 'static_cast' : cannot convert from 'void (__thiscall CKeyexeDlg::* )(WPARAM,LP
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTrunkPage::* )(void)' to 'void (__thiscall CCmdTarget::* )(N
- error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__thiscall CWnd )(WPARAM,LPARAM)”
- error C2440: ‘static_cast’ : cannot convert from ‘HRESULT (__thiscall CtestpalView::* )(WPARAM,LPARA
- error C2440: “static_cast”: 无法从“void (__thiscall CMyDlg::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscall
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESU
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- 关于自增++a,和a++的相关运算,早年的有意思的笔记
- 集合的划分
- NYOJ-813-对决-2013年11月2日23:16:37
- 编程面试的10大算法概念汇总
- Shell重定向&>file、2>&1、1>&2的区别
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTCP服务器程序Dlg::* )(WPARAM,LPARAM)'
- JXNUOJ_1023:坑爹的黑店
- 练习赛14.1,。集合的划分
- JAVA基础核心,早年的总结,今天分享
- int 不能转换为short
- Windows下使用Python读取Excel表格数据
- NYOJ-845-无主之地1-2013年11月3日00:08:18
- 进程互斥----ttylock()类似原理实现
- ZZ: linux IPV4 IPV6 sockaddr 几个结构体及其关系: sockaddr sockaddr_in sockaddr_in6