从 Shell32.dll 加载图标:Win32 句柄无效或类型错误
我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如其他答案所说
这是真的(微软从未承诺图标集永远不会改变),但不完整:
在这种情况下不存在公共合同问题,索引 71、73 和 127 处的图标无法加载,因为它们根本不存在,位置 42 和位置 133 之间的索引存在历史性的巨大差距,并逐渐被新版本的 Shell32.dll 填补。
As other answer says
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
.因为图标不是 Shell32.dll 公共合约的一部分。
无论如何,您不应该依赖从 Shell32.dll 加载图标。 Raymond Chen 解释了原因,尽管我找不到这篇文章。
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.