请教各位大侠帮忙指教error C2440: 'static_cast' : cannot convert from 'LRESULT (__thisc--------Dlg:
protected:afx_msgLRESULTOnLogMsg(DWORDdwEvent,DWORDdwLen);BEGIN_MESSAGE_MAP(CMFCSOCKS...
protected:
afx_msg LRESULT OnLogMsg(DWORD dwEvent, DWORD dwLen);
BEGIN_MESSAGE_MAP(CMFCSOCKServerSampleDlg, CDialog)
ON_MESSAGE(WM_SOCKET_RECEIVE, OnRecvMsg)
END_MESSAGE_MAP()
LRESULT CMFCSOCKServerSampleDlg::OnRecvMsg(DWORD dwEvent, DWORD dwLen)
{
if(!dwLen) return true;
BYTE* temp = new BYTE[dwLen+1];
memset(temp, 0x00, dwLen+1);
memcpy(temp, (const void*)dwEvent, dwLen);
CString log;
log.Format("接收到客户端数据=%s\r\n", (LPCTSTR)temp);
if (m_editRecv.GetLength() > 50000) m_editRecv = "";
m_editRecv += log;
UpdateData(FALSE);
return true;
}
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMFCSOCKServerSampleDlg::* )(DWORD,DWORD)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
为什么以上会出错呀??
非常感谢! 展开
afx_msg LRESULT OnLogMsg(DWORD dwEvent, DWORD dwLen);
BEGIN_MESSAGE_MAP(CMFCSOCKServerSampleDlg, CDialog)
ON_MESSAGE(WM_SOCKET_RECEIVE, OnRecvMsg)
END_MESSAGE_MAP()
LRESULT CMFCSOCKServerSampleDlg::OnRecvMsg(DWORD dwEvent, DWORD dwLen)
{
if(!dwLen) return true;
BYTE* temp = new BYTE[dwLen+1];
memset(temp, 0x00, dwLen+1);
memcpy(temp, (const void*)dwEvent, dwLen);
CString log;
log.Format("接收到客户端数据=%s\r\n", (LPCTSTR)temp);
if (m_editRecv.GetLength() > 50000) m_editRecv = "";
m_editRecv += log;
UpdateData(FALSE);
return true;
}
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMFCSOCKServerSampleDlg::* )(DWORD,DWORD)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
为什么以上会出错呀??
非常感谢! 展开
1个回答
展开全部
不能转换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)
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)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询