您的位置:首页 > 其它

VS2003转换到VS2005的一些问题

2011-11-19 14:03 441 查看
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,'|');

1. 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 many many codes like this.

2. 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 CControlbar-derived class, it compiles error:

error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CMenuBar::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' Cast 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);

3. 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 VS2005
http://hi.baidu.com/yu_xiyan/blog/item/50d58b4e9ff310c1d0c86abc.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: