验证通用 Windows 驱动程序

[在商业发行之前会发生实质性修改的、与预发布产品相关的一些信息。Microsoft 不对此处提供的信息作任何明示或默示的担保。]

你可以使用 ApiValidator.exe 工具验证你的驱动程序调用的 API 对于通用 Windows 驱动程序是否有效。如果你的驱动程序为通用 Windows 驱动程序调用的 API 不在有效 API 集中,该工具将返回一个错误。 此工具包含在适用于 Windows 10 的 Windows 驱动程序工具包 (WDK) 中。

在 Visual Studio 中运行 ApiValidator

如果你的驱动程序项目的“目标平台”属性已设置为“通用”****,则 Visual Studio 将自动运行 ApiValidator(这是后期生成步骤)。

若要查看 ApiValidator 显示的所有消息,请导航至“工具”>“选项”>“项目和解决方案”>“生成并运行”,并将“MSBuild 项目生成输出详细级别”****设置为“详细”。 在从命令行生成时,请将开关 /v:detailed/v:diag 添加至生成命令以增加详细级别。

对于 umdf2_fx2 驱动程序示例,API 验证错误如下所示:

Warning   1   warning : API DecodePointer in kernel32.dll is not supported. osrusbfx2um.dll calls this API.   C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 2   warning : API DisableThreadLibraryCalls in kernel32.dll is not supported. osrusbfx2um.dll calls this API.   C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 3   warning : API EncodePointer in kernel32.dll is not supported. osrusbfx2um.dll calls this API.   C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 4   warning : API GetCurrentProcessId in kernel32.dll is not supported. osrusbfx2um.dll calls this API. C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 5   warning : API GetCurrentThreadId in kernel32.dll is not supported. osrusbfx2um.dll calls this API.  C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 6   warning : API GetSystemTimeAsFileTime in kernel32.dll is not supported. osrusbfx2um.dll calls this API. C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 7   warning : API IsDebuggerPresent in kernel32.dll is not supported. osrusbfx2um.dll calls this API.   C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 8   warning : API IsProcessorFeaturePresent in kernel32.dll is not supported. osrusbfx2um.dll calls this API.   C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Warning 9   warning : API QueryPerformanceCounter in kernel32.dll is not supported. osrusbfx2um.dll calls this API. C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe    osrusbfx2um
Error   10  error MSB3721: The command ""C:\Program Files (x86)\Windows Kits\10\bin\x64\ApiValidator.exe" -DriverPackagePath:"C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\Debug\\" -SupportedApiXmlFiles:"C:\Program Files (x86)\Windows Kits\10\build\universalDDIs\x86\UniversalDDIs.xml" -ApiExtractorExePath:"C:\Program Files (x86)\Windows Kits\10\bin\x64"" exited with code -1.    C:\Program Files (x86)\Windows Kits\10\build\WindowsDriver.common.targets   1531    5   osrusbfx2um

Dn941247.wedge(zh-cn,VS.85).gif修复验证错误

  1. 如果你已将传统桌面驱动程序切换为通用驱动程序,请验证你是否包含正确的库。右键单击该项目并选择“属性”。 导航到“链接器”->“输入”。 “其他依赖项”****应包含:

    %AdditionalDependencies);$(SDK_LIB_PATH)\mincore.lib;$(SDK_LIB_PATH)\WppRecorderUM.lib
    
  2. 一次删除或替换一个非通用 API 调用,然后重新运行该工具,直到没有错误为止。

从命令提示符运行 ApiValidator

你还可以从命令提示符运行 Apivalidator.exe。 在 WDK 安装中,导航到 C:\Program Files (x86)\Windows Kits\10\bin\<arch>

使用以下语法:

Apivalidator.exe -DriverPackagePath:<driver folder path> -SupportedApiXmlFiles:<path to XML files containing supported APIs for universal drivers>

例如,若要验证 API 是否由 WDK 中的活动示例调用,请先在 Visual Studio 中生成该示例。 然后,打开命令提示符并导航到包含该工具的目录,例如 C:\Program Files (x86)\Windows Kits\10\bin\x64。输入以下命令:

apivalidator.exe -DriverPackagePath:"C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\Debug\\" -SupportedApiXmlFiles:"c:\Program Files (x86)\Windows Kits\10\build\universalDDIs\x64\UniversalDDIs.xml"

该命令将生成以下输出:

ApiValidator.exe: Warning: API DecodePointer in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API DisableThreadLibraryCalls in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API EncodePointer in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API GetCurrentProcessId in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API GetCurrentThreadId in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API GetSystemTimeAsFileTime in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API IsDebuggerPresent in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API IsProcessorFeaturePresent in kernel32.dll is not supported. osrusbfx2um.dll calls this API.
ApiValidator.exe: Warning: API QueryPerformanceCounter in kernel32.dll is not supported. osrusbfx2um.dll calls this API.

ApiValidator.exe Driver located at C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\Debug is NOT a Universal Driver

可为通用 Windows 驱动程序枚举有效 API 的 XML 文件位于 C:\Program Files (x86)\Windows Kits\10\build\universalDDIs\<arch> 中。

疑难解答

如果 ApiValidator.exe 输出一个格式不正确错误,如下所示:

Error      1              error : AitStatic output file has incorrect format or analysis run on incorrect file types.     C:\Program Files (x86)\Windows Kits\10\src\usb\umdf2_fx2\driver\ApiValidator.exe            osrusbfx2um

使用此解决方法:

  1. 打开“项目”属性、导航到“常规”,然后将“输出目录”****重命名为以下内容:

    $(SolutionDir)$(Platform)\$(ConfigurationName)\
    
  2. 重新构建解决方案。