相当代码量的项目,替换
工作量也是巨大的,这可不是用 名称查找、替换就能简单解决的问题,因为许多安全版本的 CRT 函数参数个数也发生了变化。也可以用预 处理指令消除这个告警: #pragma warning( disable : 4996 ) 或者定义 _CRT_SECURE_NO_WARNINGS 压制这个告警(在 stdafx.h 中 define 或在项目属性中设置 预处理符号,PreProcessor Definitions)。 除了 C 语言的 CRT 函数外, POSIX 兼容函数也存在这个告警, 解决方法是用 POSIX 标准名称替换 (比 如 access 换成_access)或者是定义 _CRT_NONSTDC_NO_WARNINGS 压制这个告警(方法同上)。
四、“CWinApp::Enable3dControls”引起的 C4996 告警 引起的 这个是编译使用了老的向导生成的 MFC 代码时遇到的问题,一个典型的告警信息输出如下所示:
CrpFileCrack.cpp f:\project\.....\crpfilecrack.cpp(52) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call. e:\software\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(4818) : see declaration of 'CWinApp::Enable3dControls' 通常向导生成的代码是:
#ifdef _AFXDLL Enable3dControls(); #else Enable3dControlsStatic(); #endif 这两个函数的调用是旧的 MFC 版本对新版本的操作系统特性的支持,在新的(那个时候是新的) Windows 95 平台上要这样调用一下才能使用新的 Windows 3D 样式的控件,否则就是老的 Win 3.2 样子的控件。想 当初喜欢 OWL 就是因为感觉它的控件比较“酷”,比如那个带底纹的对话框,菱形的 checkbox,还有带图 标的“OK”按钮,看到 MFC 作出来的灰灰的界面就觉得土,不过后来就知道 MFC 做界面也是很漂亮的,比 如我做的。。。。,再打住。对于新的 MFC 版本来说已经不需要再调用这两个函数了,参考前面的方法, 用_MSC_VER 对其隔离就行了: // Call this when linking to MFC statically // Call this when using MFC in a shared DLL
#if _M
SC_VER <= 1200 // MFC 6.0 or earlier #ifdef _AFXDLL Enable3dControls(); #else Enable3dControlsStatic(); #endif #endif 五、.def 文件引起的连接告警 对于普通的 DLL 项目中使用的.def 文件通常会引起 LNK4017 链接告警,如下所示: // Call this when linking to MFC statically // Call this when using MFC in a shared DLL
.\ComFunc.def(4) : warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored Creating library .\..\Debug/ComFunc.lib and object .\..\Debug/ComFunc.exp 一个典型的.def 文件通常有以下内容:
LIBRARY
"XorCryptor"
DESCRIPTION 'XorCryptor Windows Dynamic Link Library'
EXPORTS ; Explicit exports can go here .................. 消除这个连接告警的方法就是从.def 文件中删除 DESCRIPTION 描述信息,不过这个告警也不是什么大问 题,不删也可以。另一个可能产生的连接告警是 LNK4222,通常出现在 ocx 控件和 com 组件的项目中, 一个典型输出是:
Linking... .\PlusInModule.def : warning LNK4222: exported symbol 'DllCanUnloadNow' should not be assigned an ordinal .\PlusInModule.def : warning LNK4222: exported symbol 'DllGetClassObject' should not be assigned an ordinal .\PlusInModule.def : warning LNK4222: exported symbol 'DllRegisterServer' should not be assigned an ordinal .\PlusInModule.def : warning LNK4222: exported symbol 'DllUnregisterServer' should not be assigned an ordinal 出现这个告警的原因是旧的项目的.def 文件通常这样定义 ocx 和 com 必需的四个导出函数: EXPORTS DllCanUnloadNow DllGetClassObject DllRegisterServer DllUnregisterServer @1 PRIVATE @2 PRIVATE @3 PRIVATE @4 PRIVATE
其中为这四