我正在寻找一个工具,可以扫描windows api的兼容性,它是基于代码扫描或二进制扫描。例如,INetFwPolicy2的最低支持客户端需要Windows Vista,因此如果在XP上使用它,它将失败。我想知道是否有工具或简单的方法来挖掘这种操作系统不兼容的问题?谢谢。
发布于 2013-03-12 21:44:56
为此,您不需要“工具”;SDK头文件已经通过对版本兼容性敏感的包含保护措施进行了仔细的保护。
所有你需要做的就是在包含windows.h之前定义你的目标版本。目标版本不支持的任何符号都不会在头文件中定义,从而导致编译时错误。
例如,在预编译头中,您可能具有:
// Including SDKDDKVer.h defines the highest available Windows platform.
//
// If you wish to build your application for a previous Windows platform,
// include WinSDKVer.h and set the _WIN32_WINNT macro to the platform
// you wish to support before including SDKDDKVer.h.
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WINXP // target Windows XP
#include <SDKDDKVer.h>
#include <Windows.h>当您使用其中一个内置模板创建新项目时,Visual Studio甚至会自动执行此操作。
The SDK documentation提供了针对各种Windows版本所需的值的完整列表。但你需要的最常见的是用于Windows XP的_WIN32_WINNT_WINXP,用于Windows Vista/Server2008的_WIN32_WINNT_VISTA,用于Windows7/Server2008 R2的_WIN32_WINNT_WIN7,以及用于Windows8的_WIN32_WINNT_WIN8。
https://stackoverflow.com/questions/15362720
复制相似问题