zoukankan      html  css  js  c++  java
  • VC6.0 工程转到VS2010一些问题的描述及解决方法

    下列为VC6.0 工程转到VS2008一些问题的描述及解决方法

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1. warning:   D9035 : Fr"选项已否决,并将在将来的版本中移除
                  D9036 : 使用“FR”而不使用“Fr"

    解决方法:
         设置Project propertC/C++浏览信息启用浏览信息“无本地符号(/Fr)"---->"包含所有浏览信息(/FR);


    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2. warning : WINVER not defined. Defaulting to 0x0600(Windows Vista)

    Answer:
    #define WINVER 0x0400  
    0x0400 is for Windows NT 4.0. For Windows 2000 use 0x0500
    Note: Define it for the lowest operating system you need your app to run on, not the OS you build on.
    It defaulted to 0x0501 because you build on XP but defining it as 0x0400 will allow it to run on Windows 2000 as well.
    example: In StdAfx.h 开始时写入:
    #ifndef   WINVER
    #define   WINVER   0x0500
    #endif


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3.warning: CWinApp:: Enable3dControls() is no long need.

    这两个函数的调用是旧的MFC版本对新版本的操作系统特性的支持,在新的(那个时候是新的)Windows 95平台上要这样调用一下才能使用新的Windows 3D样式的控件,否则就是老的Win 3.2样子的控件。想当初喜欢OWL就是因为感觉它的控件比较“酷”,比如那个带底纹的对话框,菱形的checkbox,还有带图标的“OK”按钮,看到MFC作出来的灰灰的界面就觉得土,不过后来就知道MFC做界面也是很漂亮的,比如我做的。。。。,再打住。对于新的MFC版本来说已经不需要再调用这两个函数了,参考前面的方法,用_MSC_VER对其隔离就行了:

    #if _MSC_VER <= 1200 // MFC 6.0 or earlier
       #ifdef _AFXDLL
           Enable3dControls();           // Call this when using MFC in a shared DLL
       #else

      Enable3dControlsStatic();   // Call this when linking to MFC statically
       #endif
    #endif


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    4.warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss

    1. VS2008打开相应文件,再保存一遍就好了。
    2. 试一下,文件中某些地方用到的空格不是Unicode的。打开那个文件,如果文件顶层注释上面有一个空行,就把它删了试试!也需有用哦
    (1)转换Code文件为Unicode格式;
    (2)在Project -> Properties -> Configuration Properties -> C/C++ -> Advance 的 Disable Specific Warnings 中添加相应的警告编号:4819;
    (3)或找出不符合Unicode格式的文件,然后在该文件的开始处加入下面的语句:# pragma warning (disable:4819)


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    5. error C2440: ’static_cast’ : cannot convert from ‘UINT (__thiscall CStaticLink::* )(CPoint)’ to ‘LRESULT (__thiscall CWnd::* )(CPoint)’

    If you are updating from VS2003 to VS2005, C++, you might run across an error like this. What it means is that they changes the return types from 2003 to 2005. You just need to change the UINT to an LRESULT and you should be good to go.


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    6. error : "无法开启MFC42.lib"

    (推荐方法1)
    1.如果主工程下用到了一些DLL,这些DLL 是在VC6.0下编出来的,我们需要这些DLL 也在VS2008重新编译。否则在Windows7 下编译主工程会有找不到MFC42.lib 等错误。
    2. 选择静态链接MFC;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    7.处理Manifest问题
      VS2005,2008工程需要使用Manifest文件,记录“工程依赖项”。所以必须要生成Manifest文件。
      设置:Project propert linker Manifest 生成清单:是。
            Project propert linker Manifest Tool 嵌入清单:是。
    (VC6.0 没有嵌入清单的功能。需要我们自己写出Manifest放入工程,然后编入工程资源中或者放入应用程序层。但是VS2005,2008有自动生成及嵌入清单的功能)


     Manifest 文件还有一些功能: 1.设定程序运行用户权限; 2. 支持Microsoft.Windows.Common-Controls.
      1. 设定程序运行用户权限: 设置Project propert linker Manifest 启用用户帐户控制(UAC):是;
                                                                      UAC 执行极别:asInvoker (默认值);
                                                                      UAC 绕过UI保护:否;


     
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
     2.支持Microsoft.Windows.Common-Controls.
       分几种情况:如果用VS2008  则在生成工程向导中,在“高级功能设定中”,勾选“公共控件清单”项。然后编译工程时按照上述方式选择“生成清单”。清单自动生成并包含支持Microsoft.Windows.Common-Controls.

        如果创建工程时,没有设置此选项,我们可以后期在Project propert linker Manifest 附加清单依赖项:
    添加type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'

        从VC6.0升级到VS2008的工程。因为VC6.0的Manifest文件是外部的。 VS2008默认是自动生成嵌入式Manifest.所以两个会发生冲突:

        error :  CVTRES : fatal error CVT1100: duplicate resource. type:MANIFEST, name:2, language:0x0409
                 LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

    (推荐解决方案3)
    解决方案:1. Project propert linker 启用增量链接:否;(关闭增量链接)
              2. 设置工程属性->配置属性-> 清单工具->输入和输出->嵌入清单,选择[否]
              3. 在工程的.rc文件里面删除了manifest块. 删除VC6.0外部Manifest文件。设置生成嵌入式清单,并在附加清单依赖项:  Microsoft.Windows.Common-Controls。
                  (有什么时候删除VC6.0外部Manifest文件后,编译会出现问题: 嵌入清单:否;编译。。
                                                                            删除manifest块和VC6.0外部Manifest文件。编译。
                                                                            嵌入清单:是;编译。
                     这个方法或许可以解决 “删除VC6.0外部Manifest文件问题”。不肯定,请多试。             
                    )

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    8.warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

    这个问题是C语言里面某些函数的安全性检查通不过。消除Warning信息方法:

    (1)按照编译器推荐的把函数改为安全的。例如:strcpy改为strcpy_s;itoa改为_itoa_s等等;

    (2)或设置Project -> Properties -> Configuration Properties -> c/c++ -> Preprocessor -> Preprocessor Definitons里面添加 _CRT_SUCURE_NO_WARNINGS / _CRT_SUCURE_NO_DEPRECATE


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::Co.....
    解决方法,
     Property page ->C/C++ ->Language ->treat Wchar-t  改为 No

    =======================================================================================

    1.

    lesson 8
    组合框测试:格式->测试对话框;esc退出;
    又出现了“ID_PROP”:未声明的标识符,直接把#include "Resource.h"加到"stdafx.h"里;
    又出现了为类添加虚函数,在类属性窗口中选择“重写”项添加即可;


    2.
    error C2146: 语法错误 : 缺少“;”(在标识符“PVOID64”的前面)

    改动SDK的头文件,不是一个好的办法,会降低代码的移植性。

    在stdafx.h的开头,加上如下代码:

    #ifndef POINTER_64

    #if !defined(_MAC) && (defined(_M_MRX000) || defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
    #define POINTER_64 __ptr64
    typedef unsigned __int64 POINTER_64_INT;
    #if defined(_WIN64)
    #define POINTER_32 __ptr32
    #else
    #define POINTER_32
    #endif
    #else
    #if defined(_MAC) && defined(_MAC_INT_64)
    #define POINTER_64 __ptr64
    typedef unsigned __int64 POINTER_64_INT;
    #else
    #if (_MSC_VER >= 1300) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
    #define POINTER_64 __ptr64
    #else
    #define POINTER_64
    #endif
    typedef unsigned long POINTER_64_INT;
    #endif
    #define POINTER_32
    #endif

    #endif

    =================================================================================

    1.
    WINVER not defined. Defaulting to 0x0600 (Windows Vista)
    #ifndef WINVER                          // Specifies that the minimum required platform is Windows Vista.
             #define WINVER 0x0501          // Change this to the appropriate value to target other versions of Windows.
             #endif

    添加上面代码到stdafx.h中
    2.
    error C2259: “CException”: 不能实例化抽象类
    MFC较好地将异常封装到CException类及其派生类中,自成体系,下表给出了MFC 提供的预定义异常:CMemoryException:内存不足
    CFileException:文件异常
    CArchiveException:存档/序列化异常
    CNotSupportedException:响应对不支持服务的请求
    CResourceException:Windows 资源分配异常
    CDaoException:数据库异常(DAO 类)
    CDBException:数据库异常(ODBC 类)
    COleException:OLE 异常
    COleDispatchException:调度(自动化)异常
    CUserException:用消息框警告用户然后引发一般 CException 的异常
    所以只要把上面的CException与异常类相对应的.比如文件异常,改成CFileException.
    代码中采用将所有的CException改成了CFileException
    3.
    无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
    1.菜单中选择 Project->Properties, 弹出Property Pages窗口
    2.在左边栏中依次选择:Configuration Properties->C/C++->Preprocessor,然后在右边栏的Preprocessor Definitions对应的项中删除_CONSOLE, 添加_WINDOWS.
    3.在左边栏中依次选择:Configuration Properties->Linker->System,然后在右边栏的SubSystem对应的项改为Windows(/SUBSYSTEM:WINDOWS)
    4.Rebuild All. Ok ?
    4.
    error C2039: “WriteHuge”: 不是“CFile”的成员
    error C2039: “ReadHuge”: 不是“CFile”的成员
    把Huge去掉即

  • 相关阅读:
    初识Java8新特性Lambda(二) 之collections
    hadoop-2.5.0-cdh5.3.6 native包 替换
    初识Java8新特性Lambda(三 ) 之lambda类库Stream
    初识Java8新特性Lambda(一)
    js将文件流转为文件
    验证有效的外部链接
    gb2312编码转换
    Beautiful Soup4
    chromedriver版本下载
    redmine使用post登录,cookie使用
  • 原文地址:https://www.cnblogs.com/duyy/p/3594215.html
Copyright © 2011-2022 走看看