windows - 如何 link 对抗 API 集 (*ms-win*) 而不是 kernel32.dll、ntdll.dll 等?

windows - how to link against API sets (*ms-win*) instead kernel32.dll, ntdll.dll etc.?

如何针对 API sets*ms -win* 模式匹配 dll) 而不是 kernel32.dll, ntdll.dll 等?

例如,我创建了一个简单的 dll,它只调用了一些基本的 WinAPI。检查它的 IAT 时(通过 CFF Explorer, python pefile 库等)只有 kernel32.dll。 我想要发生的是看到 *ms-win* dll。

API 集在内部使用,这意味着 'legacy' 7、8 或 10 上的 'legacy' 系统 DLL 也使用它们。因此,您没有理由需要直接使用它们。

也就是说,您可以使用许多 'umbrella' 库而不是链接到经典 KERNEL32.DLL 等库:

  • onecore.lib
  • onecoreuap.lib
  • onecore_apiset.lib

请记住,它们旨在匹配与它们附带的 Windows 10 SDK 相同的 Windows 构建(即它们向前兼容,而不是向后兼容)。还有 *_downlevel.lib 版本支持 Windows 的旧版本。这些主要供驱动程序开发人员使用 Microsoft Docs

UWP 应用程序使用自己的伞形库 WindowsApps.lib / WindowsApps_downlevel.lib.

有关 umbrella 库 的更多信息,请参阅 Microsoft Docs

Note that you should not link with more than one umbrella library, and you shouldn't mix kernel32.lib with umbrella libraries in the same link. This is actually a bit challenging to do with MSBuild default rules for scenarios other than WindowsApps.lib. There's an improvement coming in VS 2022 17.2 that addresses this. See this VS feedback issue.

Also due to a quirk of the Microsoft Visual C/C++ Runtime, if you are linking with onecore_apiset.lib, you should use /IGNOREDEFAULTLIB:onecore.lib /IGNOREDEFAULTLIB:kernel32.lib as well. It's also a good idea to use /SUBSYSTEM:WINDOWS,10.0 or /SUBSYSTEM:CONSOLE,10.0. See this VS feedback issue.