VC6 和 VS2003 转换到 VS2005 时可能会遇到的问题以及解决方法
今天在将 2003 建立的工程转换成 2005 时,发现遇到很多问题,网上搜了一些解决办法: 时出现的各种各样的问题, 经常写 VC 工程的人都会遇到升级到 VS2005 时出现的各种各样的问题,下面写一 些自己遇到的问题,还有什么不全的请大家补充。希望能给朋友们一些帮助。 些自己遇到的问题,还有什么不全的请大家补充。希望能给朋友们一些帮助。
VC6 和 VS2003 转换到 VS2005 时可能会遇到的问题以及解决方法
1.以前可以这样用 try catch 以前可以这样用 catch(CException *e) { pApp->Warn("%s",e->GetErrorMessage); e->Delete(); return FALSE; } 现在必须修改为: 现在必须修改为: catch(CException *e) { TCHAR errormsg[255]; e->GetErrorMessage (errormsg,255,NULL); pApp->Warn("%s",errormsg); e->Delete(); return FALSE;
}
2. strchr 必须强制转换一下。 必须强制转换一下。 以前可以 char *str2=strchr(line,'|'); 2005 必须 char *str2=(char *)strchr(line,'|');
3.lifescope of int i in for(int i; i< size; ++i)in VC6, the codes below are ok for(int i = 0; i< 10; ++i) { //... } for(i = 20; i< 40;++i) { //... } but in VS2005, we should write like below: for(int i = 0; i< 10; ++i) { //... } for(int i = 20; i< 40;++i)
{ //... } in fact, from vs.net, the compiler accord with C++ standard more than VC6. If you are porting a VC6 project to VS2005, you will encounter ma ny many codes like this. 4. ON_WM_NCHITTEST (and other MFC macros) won't compile in VS2005 VS2005 中,ON_WM_NCHITTEST 宏编译不过 When I add a message handler of ON_WM_NCHITTEST to a CCont rolbar-derived class, it compiles error: error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CMenuBar::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' Ca st from base to derived requires dynamic_cast or static_cast To fix this bug, we should change the prototype of OnNcHitTest from afx_msg UINT OnNcHitTest(CPoint point); to afx_msg LRESULT OnNcHitTest(CPoint point); 5. VS2005 中有些可能引起内存越界的函数不建议使用了 In VS2005, some dangerous functions are deprecated char c[10]; strcpy(c, "testtestts"); //ok with VC6, but not in VS2005 strcpy_s(c, _countof(c),"testtestt");//9 chars, ok in VS2005
strcpy_s(c, _countof(c),"testtestt");//10 chars, assert!!!!! in VS2 005 6. error C2440: 'static_cast' : cannot convert from 'HRESULT (__this call CtestpalView::* )(WPARAM,LPARAM)' to 'AFX_PMSG' None of the functions with this name in scope match the targ et type HRESULT (__thiscall CtestpalView::* )(WPARAM,LPARAM) AFX_PMSG 类型: void (AFX_MSG_CALL CCmdTarget::* )(void) 7. error C2440: 'static_cast' : cannot convert from 'void (__thiscall C SettingStart::* )(BOOL,HANDLE)' to 'void (__thiscall CWnd::* )(BOOL, DWORD)' In VC6, the handler for ON_WM_ACTIVATEAPP was expected to b e afx_msg void OnActivateApp( BOOL, HANDLE); In
VC7 and vs2005, it has been changed to afx_msg void OnActivateApp( BOOL, DWORD ); 8. error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::Co..... 解决方法, 解决方法, Property page ->C/C++ ->Language ->treat Wchar-t 改为 No 未完待续...... 未完待续
官方总结: 官方总结
Visual C++ 2005 库已经发生了一系列的变化,可能会对现有的程序有所影响, 库已经发生了一系列的变化,可能会对现有的程序有所影响, 之前,必须要确定程序中没有这些问题。 在升级到 Visual C++ 2005 之前,必须要确定程序中没有这些
问题。 1、参数的有效性 、 运行时库中,加入了一些代码,以检查