从 Shell32.dll 加载图标:Win32 句柄无效或类型错误

发布于 2024-07-23 00:03:11 字数 575 浏览 8 评论 0原文

我从 Shell32.dll 获取一些图标。 虽然有些图标似乎不可用,但我不明白为什么。

我通过调用加载库来获取图标:

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string Library);

然后通过调用获取图标:

    [DllImport("User32.dll")]
public static extern IntPtr LoadImage(IntPtr ptr, int intId, uint intType, int iconWidth,  int iconHeight, int loadIcon);

我发送了我正在获取的图标的图标索引,这对于诸如打开文件夹图标(索引 5)和登录图标(索引 45),但是当我尝试获取索引处的图标(71、73、127 等)时,出现以下异常: 传递给 Icon 的 Win32 句柄无效或者类型错误

我想知道是否有人知道为什么会发生这种情况? 以及为什么有些图标可以访问,而另一些则无法访问。

谢谢

I am getting some Icons from the Shell32.dll. Althought some of the icons don't appear to be available, and I can't understand why.

I am getting the icon by loading the library by calling:

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string Library);

and then getting the icon by calling:

    [DllImport("User32.dll")]
public static extern IntPtr LoadImage(IntPtr ptr, int intId, uint intType, int iconWidth,  int iconHeight, int loadIcon);

I send in the icon index of the icon that I am getting, which works fine for icpons such as the Open Folder Icon (index 5) and LogIn icon (Index 45) but when i try and get icons at index (71, 73, 127, etc. etc.) I get the following exception:
Win32 handle that was passed to Icon is not valid or is the wrong type

I was wondering if anyone knew why this was happening? and why some of the icons are accessible and others appear not.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一杯敬自由 2024-07-30 00:03:13

正如其他答案所说

因为图标不是 Shell32.dll 公共合约的一部分。

无论如何,您都不应该依赖从 Shell32.dll 加载图标。

这是真的(微软从未承诺图标集永远不会改变),但不完整:

在这种情况下不存在公共合同问题,索引 71、73 和 127 处的图标无法加载,因为它们根本不存在,位置 42 和位置 133 之间的索引存在历史性的巨大差距,并逐渐被新版本的 Shell32.dll 填补。

As other answer says

Because the icons are not part of the public contract of Shell32.dll.

You shouldn't rely on loading icons from Shell32.dll anyway.

which is true (Microsoft never promises the icon set will never change), but not complete:

There is no problem of public contract in this case, the icons at indexes 71, 73 and 127 cannot be loaded because they just don't exist, there is a historical huge gap in indexes between positions 42 and 133, gradually filled by new versions of Shell32.dll.

亣腦蒛氧 2024-07-30 00:03:12

为什么有些图标可以访问,而另一些图标却无法访问。

因为图标不是 Shell32.dll 公共合约的一部分。

无论如何,您不应该依赖从 Shell32.dll 加载图标。 Raymond Chen 解释了原因,尽管我找不到这篇文章。

why some of the icons are accessible and others appear not.

Because the icons are not part of the public contract of Shell32.dll.

You shouldn't rely on loading icons from Shell32.dll anyway. Raymond Chen explains why, though I can't find the article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文