哪个 DLL 有 PathCchAppend?

Which DLL has PathCchAppend?

我正在尝试有条件地使用(如果可用)函数PathCchAppend。我从 header pathcch.h 得到了函数签名。但是,当我尝试从 SHLWAPI.DLL 获取函数地址时,它失败了:

auto pca = GetProcAddress(GetModuleHandle(L"shlwapi.dll"), "PathCchAppend");

使用Depends,我看到这个函数在这个DLL中不存在(我在Windows 10)。不存在任何 pathcch.dll,因此也无法加载它。

这个函数放在哪个DLL里?

编辑: 感谢答案。在这里,我找到了以下答案中提到的 DLL 名称:

https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-81-api-sets

您可以使用 DUMPBIN 工具从 .lib 文件中提取此信息:

dumpbin /headers /path/to/pathcch.lib

然后您需要筛选输出以找到有问题的函数。例如,这是 x64 版本的 lib 文件的输出:

  Version      : 0
  Machine      : 8664 (x64)
  TimeDateStamp: FFFFFFFF Sun Feb 07 06:28:15 2106
  SizeOfData   : 0000002E
  DLL name     : api-ms-win-core-path-l1-1-0.dll
  Symbol name  : PathCchAppend
  Type         : code
  Name type    : name
  Hint         : 5
  Name         : PathCchAppend

关于硬编码此DLL名称的向后和向前兼容性的评论,.lib文件硬编码DLL名称。因此,如果您 link 使用 .lib 文件访问该函数,那么您就是在硬编码对该 DLL 的依赖性。这将 Microsoft 绑定到一个合同中,以便在 Windows 的未来版本中继续从此 DLL 中导出此功能。因此,显式使用 LoadLibrary/GetProcAddress link 并不比隐式使用 SDK 中的 .lib 文件 link 安全。

api-ms-win-core-path-l1-1-0.dll 不是实际的 DLL 也不是磁盘上的文件,而只是一些虚拟名称,因此加载程序最终能够将请求映射到文件上的某个磁盘。扩展 DLL 按惯例使用或仅作为加载程序的系统要求使用,但并不意味着任何文件。

You can use an API set name in the context of a loader operation such as LoadLibrary or P/Invoke instead of a DLL module name to ensure a correct route to the implementation no matter where the API is actually implemented on the current device. However, when you do this you must append the string .dll at the end of the contract name. This is a requirement of the loader to function properly, and is not considered actually a part of the contract name. Although contract names appear similar to DLL names in this context, they are fundamentally different from DLL module names and do not directly refer to a file on disk.

https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-apisets#api-set-contract-names

所以问题的真正答案是KernelBase.dll。这对于 use cases like mine, where I need to create a lib file based on an actual DLL, which is only possible with KernelBase.dll. MS maintains some additional docs 使某些 API 集的基础文件也可用很重要。