从VC6迁移到VS2005 - MESSAGE

来源:互联网 发布:安卓手机恢复数据 编辑:程序博客网 时间:2024/04/28 20:20

    在迁移一个CRC32程序时,遇到如下问题:

    编译日志:

    

1>------ Rebuild All started: Project: CRCThread, Configuration: Debug Win32 ------1>Deleting intermediate and output files for project 'CRCThread', configuration 'Debug|Win32'1>Compiling...1>StdAfx.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>Compiling...1>CRC_32.cpp1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\crc_32.cpp(95) : warning C4996: '_sopen': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.1>        c:\program files\microsoft visual studio 8\vc\include\io.h(255) : see declaration of '_sopen'1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\crc_32.cpp(311) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.1>        c:\program files\microsoft visual studio 8\vc\include\tchar.h(1518) : see declaration of '_tcsncpy'1>CRCThread.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\crcthread.cpp(52) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(4477) : see declaration of 'CWinApp::Enable3dControls'1>CRCThreadDlg.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\crcthreaddlg.cpp(103) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CCRCThreadDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>FileEditCtrl.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\fileeditctrl.cpp(277) : error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CFileEditCtrl::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'1>        Cast from base to derived requires dynamic_cast or static_cast1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\fileeditctrl.cpp(285) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CFileEditCtrl::* )(UINT,LPCTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\fileeditctrl.cpp(1897) : warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized1>PJA_Icon.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>TextProgressCtrl.cpp1> WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\textprogressctrl.cpp(157) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CTextProgressCtrl::* )(UINT,LPCTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\textprogressctrl.cpp(158) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CTextProgressCtrl::* )(UINT,LPTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\textprogressctrl.cpp(165) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\textprogressctrl.cpp(166) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>d:\mydoc09\visual studio 2005\projects\crc32\codeproject2\crc_32_demo\textprogressctrl.cpp(170) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'1>        None of the functions with this name in scope match the target type1>Generating Code...1>Build log was saved at "file://d:\mydoc09\Visual Studio 2005\Projects\crc32\codeproject2\CRC_32_Demo\Debug\BuildLog.htm"1>CRCThread - 8 error(s), 4 warning(s)========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

其中的错误大多与"

 error C2440: 'static_cast' : cannot convert from
"静态转换有关。

主要说某个参数无法转换到另一个类型。

看MSDN关于消息影射相关规定:

Map entry

Function prototype

ON_MESSAGE( <message>, <memberFxn> )

afx_msg LRESULT memberFxn( WPARAM, LPARAM );

ON_REGISTERED_MESSAGE( <nMessageVariable>, <memberFxn> )

afx_msg LRESULT memberFxn( WPARAM, LPARAM );

ON_THREAD_MESSAGE( <message>, <memberFxn> )

afx_msg void memberFxn( WPARAM, LPARAM );

ON_REGISTERED_THREAD_MESSAGE( <nMessageVariable>, <memberFxn> )

afx_msg void memberFxn( WPARAM, LPARAM );


一、简单升级错误:

1)OnSetText

原声明:afx_msg LRESULT OnSetText(UINT, LPCTSTR)

更改为:afx_msg LRESULT OnSetText(WPARAM, LPARAM)

2)OnCRCThreadDone

原声明:afx_msg void OnCRCThreadDone(WPARAM, LPARAM);

更改为:afx_msg LRESULT OnCRCThreadDone(WPARAM, LPARAM);

3)OnGetText

原声明:afx_msg LRESULT OnGetText(UINT cchTextMax, LPTSTR szText);

更改为:afx_msg LRESULT OnGetText(WPARAM cchTextMax, LPARAM szText);

4)OnSetRange

原声明:afx_msg void      OnSetRange(WPARAM, LPARAM range);

更改为:afx_msg LRESULT     OnSetRange(WPARAM, LPARAM range);

5)OnSetRange32

原声明:afx_msg void      OnSetRange32(WPARAM lower, LPARAM higher);

更改为:afx_msg LRESULT      OnSetRange32(WPARAM lower, LPARAM higher);

6)OnSetShowText

原声明:afx_msg void      OnSetShowText(WPARAM bShow, LPARAM);

更改为:afx_msg LRESULT      OnSetShowText(WPARAM bShow, LPARAM);


二、VC系统函数更改后的错误

1)ON_WM_NCHITTEST

出现这个错误的原因可是“人力不可抗拒”之原因造成的,因为旧版本的 ON_WM_NCHITTEST 宏使用了

UINT (__thiscall CWzButton::* )(CPoint);

类型的类成员函数指针,其定义如下:

#define ON_WM_NCHITTEST() \
{ WM_NCHITTEST, 0, 0, 0, AfxSig_wp, \
(AFX_PMSG)(AFX_PMSGW)(UINT (AFX_MSG_CALL CWnd::*)(CPoint))&OnNcHitTest },


但是新版本变成了:

#define ON_WM_NCHITTEST() \
{ WM_NCHITTEST, 0, 0, 0, AfxSig_l_p, \
(AFX_PMSG)(AFX_PMSGW) \
(static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(CPoint) > (&ThisClass :: OnNcHitTest)) },
UINT (__thiscall CWzButton::* )(CPoint);

修改的方法就是将你的OnNcHitTest函数由:

afx_msg UINT OnNcHitTest(CPoint point);

改成:

afx_msg LRESULT OnNcHitTest(CPoint point);

======================================================================本文 End==

这个程序是用在大文件下多线程CRC32的校验。

VC6版本的链接

VC8版本的链接