Reputation: 18760
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
Upvotes: 1
Views: 6202
Reputation: 338
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
.
Upvotes: 2
Reputation: 23759
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.
Upvotes: 2