c++ - windows - 如何链接 API 集 (*ms-win*) 而不是 kernel32.dll、ntdll.dll 等?

标签 c++ windows winapi visual-studio-2015 linker

我如何明确指定 MSVC 编译器/链接器链接到 API sets (*ms-win* 模式匹配 dll)而不是 kernel32.dllntdll.dll 等?

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

最佳答案

API 集在内部使用,这意味着即使是 Windows 7、8 或 10 上的“遗留”系统 DLL 也会使用它们。因此,您没有理由需要直接使用它们。

也就是说,您可以使用许多“伞式”库,而不是链接到经典的 KERNEL32.DLL 等:

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

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

UWP 应用使用它们自己的伞形库 WindowsApps.lib/WindowsApps_downlevel.lib

参见 Microsoft Docs有关umbrella 库的更多信息。

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.

关于c++ - windows - 如何链接 API 集 (*ms-win*) 而不是 kernel32.dll、ntdll.dll 等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65662707/

相关文章:

c++ - Socket select() 第二次阻塞

c++ - 为什么浮点类型对于模板函数来说是无效的模板参数类型?

Python:无法轻松安装 (Windows 7 x64)

windows - 如何在 Windows 中使用 H264 视频编码器 MFT 对位图进行编码

c++ - 输入法管理器函数 - 平假名到汉字候选列表 c++ 转换的正确调用顺序

python - C++/嵌入式 Python : Can I retrieve Python file name and line number when a C++ function is called from Python

c++ - gtkmm 的 g_signal_emit 或 g_signal_emit_by_name 版本是什么?

c# - 来自 C# : why do I have to override new/delete? 的 mingw DLL

c++ - 如何获取USB设备列表

c++ - 如何防止箭头键改变 UI 状态?