寻找可以扫描windows api兼容性问题的工具

时间:2013-03-12 13:34:26

标签: windows winapi visual-c++ testing

我正在寻找一种可以扫描windows api兼容性的工具,它可以基于代码扫描或二进制扫描。例如,INetFwPolicy2的最低支持客户端需要Windows Vista,因此如果在XP上使用它,它将失败。我想知道是否有工具或简单的方法来挖掘这种操作系统不兼容的问题? 感谢。

1 个答案:

答案 0 :(得分:2)

你不需要一个“工具”; SDK标头已经过使用对版本兼容性敏感的包含保护措施进行了小心保护。

您需要做的就是在包含windows.h之前定义Windows 的目标版本。目标版本支持的任何符号甚至不会在头文件中定义,从而导致编译时错误。

例如,在预编译的标题中,您可能有:

// 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 / Server 2008 _WIN32_WINNT_VISTA,Windows 7 / Server 2008 R2 _WIN32_WINNT_WIN7_WIN32_WINNT_WIN8对于Windows 8。