LibraryImportAttribute 的 DefaultDllImportSearchPathsAttribute 行为

问题描述 投票:0回答:1

按照平台调用的源生成中所述从DllImportAttribute迁移到LibraryImportAttribute,我偶然发现了DefaultDllImportSearchPathsAttribute,它指定了用于搜索DLL的路径。

假设我有以下DLL导入,

[DllImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);

更新为

[LibraryImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static partial bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);

,搜索路径也会像以前一样由 LibraryImportAttribute 处理吗?

c# .net dllimport libraryimport
1个回答
0
投票

正如评论中已经指出的,答案是肯定的,

DefaultDllImportSearchPaths 也将由 LibraryImport 处理

可以在 .NET 源代码中看到,LibraryImportGenerator.cs 处理 DllImportSearchPathsAttribute。 使用一些最小的示例可执行文件对其进行反编译和测试也证实了这一点。

© www.soinside.com 2019 - 2024. All rights reserved.