新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → VC6到VS2010中的转换 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 8674 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: VC6到VS2010中的转换 举报  打印  推荐  IE收藏夹 
       本主题类别: Description Logics    
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 Dot NET,C#,ASP,VB 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 VC6到VS2010中的转换


    1、 error C2668: 'sqrt' : ambiguous call to overloaded function

         在VS2005中存在sqrt函数的重载。当编译器看到sqrt(int)时,找不到相应的函数,此时存在sqrt(float)和sqrt(long double)两个函数,编译器不知道程序员需要哪个函数,就会出现错误。可以使用sqrtf( )代替。

    2、 error C2039: 'ReadHuge' : is not a member of 'CFile

         VS2005中,readhuge被read包括了。

    3、 error C2668: 'pow' : ambiguous call to overloaded function

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

    4. 以前可以这样用try catchcatch(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;

         }5. strchr必须强制转换一下。以前可以 char *str2=strchr(line,'|');

    2005必须 char *str2=(char *)strchr(line,'|');6. 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.7. ON_WM_NCHITTEST (and other MFC macros) won't compile in VS2005VS2005中,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);8. 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 VS20059.error C2440: 'static_cast' : cannot convert from 'HRESULT (__thiscall CtestpalView::* )(WPARAM,LPARAM)' to 'AFX_PMSG'

             None of the functions with this name in scope match the target type

    HRESULT (__thiscall CtestpalView::* )(WPARAM,LPARAM)

    AFX_PMSG类型:

    void (AFX_MSG_CALL CCmdTarget::* )(void)

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

    In VC6, the handler for ON_WM_ACTIVATEAPP was expected to be

    afx_msg void OnActivateApp( BOOL, HANDLE);

    In VC7 and vs2005, it has been changed to

    afx_msg void OnActivateApp( BOOL, DWORD );

    11.error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::Co.....

    解决方法,

    Property page ->C/C++ ->Language ->treat Wchar-t   改为 No

    a. ON_MESSAGE(message,OnMyMessage);OnMyMessage返回值必须为LRESULT,其形式为:afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);如果不符合,则有错误提示:error C2440: “static_cast”: 无法从“void (__thiscall CPppView::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”

    在匹配目标类型的范围内没有具有该名称的函数

    error C2440: “static_cast”: 无法从“void (__thiscall CPppView::* )(void)”转换为“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”

    在匹配目标类型的范围内没有具有该名称的函数

    b. ON_COMMAND_EX(id,OnMyMessage2);

    在VS2005中,OnMyMessage返回值必须为BOOL,且含有一个 UINT 参数指出了命令ID,其形式为:afx_msg BOOL OnMyMessage(UINT);如果不符合,

    则有错误提示,如在VS6中,OnMyMessage2的定义为afx_msg BOOL OnViewZoomBar()时亦可正常编译通过,但在VS2005下,有错误提示:

    error C2440: “static_cast”: 无法从“BOOL (__thiscall CMainFrame::* )(void)”转换为“BOOL (__thiscall CCmdTarget::* )(UINT)”

    在匹配目标类型的范围内没有具有该名称的函数

     error C2440: “static_cast”: 无法从“BOOL (__thiscall CMainFrame::* )(void)”转换为“BOOL (__thiscall CCmdTarget::* )(UINT)”

    在匹配目标类型的范围内没有具有该名称的函数

    13. 字符处理

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

    14. 数学函数检查

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

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

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

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

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

    试图匹配参数列表“(int, int)”时

    正确的使用为pow(2.0, 45)

    15. 更加符合C++标准

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

    VC6:

    for(int i=0;i<100;i++)f2();

    for(i = 1;i<10;i++)f1(); //i已经定义

    而有VS2005中,第二句的i必须重新定义。16. A WM_COMMAND handler has always the following signaturevoid OnFunc();

    17. A message handler has always this signature     LRESULT OnMsgHandler(WPARAM wparam, LPARAM lparam);

    So you have to write 2 handlers:

    The map entries:ON_COMMAND(ID_BTN_ASINCRONICO, OnBtnAsincronico)

    ON_MESSAGE(WM_APP_NOSINCRONICO, OnBtnAsincronico)The header file declaration:afx_msg LRESULT OnBtnAsincronico(WPARAM wparam, LPARAM lparam);

    afx_msg void OnBtnAsincronico();The definition:LRESULT CMainFrame:nBtnAsincronico(WPARAM /*wparam*/, LPARAM /*lparam*/)

    {

    OnBtnAsincronico();

    return 0;

    }void CMainFrame:nBtnAsincronico(){

    ...

    }18.CDlg *dlg=new CDlg;

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

    error C2660: 'Create' : function does not take 2 parameters且我将第二个参数去掉的时候,又会显示

    error C2660: 'Create' : function does not take 1 parameters19.error C2871: 'System' : a namespace with this name does not exist

    这个错误只能说VC编译器还不够智能啊

    在使用前需要使用Common Language Runtime Support (/clr).

    在配置属性中,选择general-》选择clc (Configuration Properties/General/Common Language Runtime support)


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/10/26 17:36:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/15 18:58:03

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    8,421.875ms