设为首页 加入收藏

TOP

VC6.0转VS2005问题及解决办法(一)
2014-11-23 19:02:13 】 浏览:511
Tags:VC6.0 VS2005 问题 解决 办法

我对原文的内容加以整理,便于阅读,以后发现新的转换问题,将会继续补充,

也欢迎大家跟帖提出新的问题并解决办法,帮助我继续完善,谢谢!


一. 函数原型改变导致的问题

1. errorC2440:CMainFrame 无法从 NMTOOLBARA 转换为 NMHDR

VC6下OnToolbarDropDown的函数原型:

[cpp]
voidCMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
需要改为:
[cpp]
void CMainFrame::OnToolbarDropDown(NMHDR*pnmhdr, LRESULT *plr)
{
LPNMTOOLBAR pnmtb =reinterpret_cast(pnmhdr);
// ...
}
2. error C2668: 'sqrt' : ambiguouscall to overloaded function
原因:在VS2005中存在sqrt函数的重载。当编译器看到sqrt(int)时,找不到相应的函数,此时存在sqrt(float)和sqrt(long double)两个函数,编译器不知道程序员需要哪个函数,就会出现错误。

解决办法:可以使用sqrtf( )代替。

3. error C2039: 'ReadHuge' : isnot a member of 'CFile

原因:VS2005中,readhuge被read包括了。

4. error C2668: 'pow' : ambiguouscall to overloaded function

在VS2005中,需要写成pow((double)i, 2),原因我没有查到。
在VS2005中,函数原型为 double__cdecl pow(__in double _X, __in double _Y);

在VC6中,函数原型为_CRTIMP double __cdecl pow (double, double);

5.ON_WM_NCHITTEST (and other MFCmacros) won't compile in VS2005。

VS2005中,ON_WM_NCHITTEST宏编译不过:

error C2440: 'static_cast' : cannot convertfrom 'UINT (__thiscall CMenuBar::* )(CPoint)' to 'LRESULT (__thiscall CWnd::*)(CPoint)' Cast from base to derived requires dynamic_cast or static_cast

解决办法:修改OnNcHitTest的原型:

VC6:afx_msg UINT OnNcHitTest(CPointpoint); ->

VS2005:afx_msg LRESULT OnNcHitTest(CPointpoint);

6. error C2440: 'static_cast' :cannot convert from 'void (__thiscall CSettingStart::* )(BOOL,HANDLE)' to 'void(__thiscall CWnd::* )(BOOL,DWORD)'

ON_WM_ACTIVATEAPP 的消息处理函数原型:

VC6:afx_msg void OnActivateApp( BOOL,HANDLE);

VS2005:afx_msg void OnActivateApp( BOOL,DWORD );


二. 其它问题

1. 以前可以这样用try

[cpp]
catch(CException*e)
{
pApp->Warn("%s",e->GetErrorMessage);

e->Delete();

return FALSE;

}
现在必须修改为:

[cpp]
catch(CException*e)
{
TCHAR errormsg[255];
e->GetErrorMessage(errormsg,255,NULL);
pApp->Warn("%s",errormsg);
e->Delete();
return FALSE;
}
2. strchr必须强制转换一下。
VC6:char *str2=strchr(line,'|');

VS2005: char *str2=(char *)strchr(line,'|');

3. VS2005中有些可能引起内存越界的函数不建议使用。

[cpp]
char c[10];
strcpy(c, "testtestts"); //ok with VC6, but not in VS2005
strcpy_s(c, _countof(c),"testtestt");//9 chars, ok inVS2005
strcpy_s(c, _countof(c),"testtestt");//10 chars,assert!!!!! in VS2005
4. error LNK2019: unresolvedexternal symbol "wchar_t * __stdcall _com_util::Co.....
解决方法:Property page ->C/C++ ->Language ->treatWchar-t 改为 No

5. 字符处理

在c中广泛使用的strcpy,strcat,strstr等等推荐使用更为安全的strcpy_s,strcat_s,strstr_s等来代替。

6. 数学函数检查

 VS2005中,数学函数的参数检查更为严格,如pow(2, 45)会引起一个错误提示如下:

error C2668: “pow”: 对重载函数的调用不明确

d:\program files\microsoft visual studio8\vc\include\math.h(575): 可能是“long double pow(long double,int)”

d:\program files\microsoft visual studio8\vc\include\math.h(527): 或“float pow(float,int)”

d:\program files\microsoft visual studio8\vc\include\math.h(489): 或“double pow(double,int)”

试图匹配参数列表“(int, int)”时,正确的使用为pow(2.0, 45)

7. 更加符合C++标准

在VC6中,在for循环中的循环变量的定义的作用域延伸到循环体外,VS2005则修正了这样的bug。

在VC6中:

[cpp]
for(int i=0;i<100;i++)
{
f2();
}

for(i = 1;i<10;i++)
{ //i已经定义
f1();
}
而有VS2005中,第二个循环中的i必须重新定义。

8. Create问题

CDlg *dlg=new CDlg;

dlg->create(IDD_DLG,this);//出错之处

error C2660: 'Create' : function does nottake 2 parameters且我将第二个参

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VS2012 正式版BUG太多 下一篇VC++实现恢复SSDT

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目