Loading icons from Shell32.dll: Win32 handle is not valid or is the wrong type

巧了我就是萌 提交于 2020-01-05 08:32:56

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/949196/loading-icons-from-shell32-dll-win32-handle-is-not-valid-or-is-the-wrong-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!