vc6.0项目升级到vs2010过程中遇到的所有问题
1.warning:_WIN32_WINNT not defined.Defaulting to _WIN32_WINNT_MAXVER.
原因:Vc6.0中对_WIN32_WINNT设置太老了,为:
#define _WIN32_WINNT 0x0400 //////(在stdafx.h文件中)
解决办法:修改该句为:
#define _WIN32_WINNT 0x0502 ////设成0x0500也是可以的。
2,warning C4996: CWinApp::Enable3dControls is no longer needed. You should remove this call.
错误出在:MyProject.h中Instance()函数中。
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
解决办法:添加屏蔽代码,即为:
#if _MSC_VER <=1200
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
#endif
3,Warning:’strcpy’:This function or variable may be unsafe, Consider using strcpy_s instead.
原因在于C库的很多函数内部是不进行参数检测的,微软便改写这些函数,使之更安全便捷。
解决办法为:将strcpy换成strcpy_s
类似的情况有:sprintf换成sprintf_s
4.error:
”static_cast”无法从void(_thiscallCTreColorToolBar::*(NMTOOLBARA*,LRESULT*)转换成void(_thiscallCCmdTarget::*(NMHDR*,LRESULT*)
原因:错误出现在 ON_NOTIFY_REFLECT(TBN_DROPDOWN,OnToolbarDropDown),具体原因,尚未得知,网上搜索的法子。
解决办法:修改OnToolbarDropDown的函数声明。具体如下:
在.h文件中修改参数类型为:afx_msg void OnToolbarDropDown(NMHDR* pnmh, LRESULT* plRes);
回到.cpp文件OnToolbarDropDown函数的定义处,修改为
voidCTrueColorToolBar::OnToolbarDropDown(NMHDR* NMHDRpnmtb, LRESULT *plr)
{
NMTOOLBARA *pnmtb=(NMTOOLBARA*)NMHDRpnmtb;///作为第一句,下面的代码不用更改
}
5.Debug Assertion Failed.
原因:内存溢出,程序崩溃,调试发现是从开始执行App.cpp文件的InitInstance()函数ProcessShellCommand(cmdInfo)这句时发生中断的。
解决过程:对话框中定义的某些控件被删除后,其曾经定义的变量未随之删除,这会导致上述现象发生。但删除那些变量后,程序依旧崩溃。继续追踪调试程序,发现执行到AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL)时程序再次崩溃。之后发现是默认的文档名为空,这次的解决办法是:在资源视图中,点击
String Table找到IDR_MYFRAME(自己重新定义的主菜单),(假如程序名为MyTest)修改为:
MyTest\nMyTest\nMyTest\n\n\nMyTest.Document\nMyTest Document