tags:

views:

1124

answers:

1

Hi,

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  A: 

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.

OregonGhost
http://blogs.msdn.com/oldnewthing/archive/2005/10/26/485133.aspx - When programs assume that the system will never change, episode 1?
1800 INFORMATION
Yes, that's at least one of the articles. I think he wrote several about this ;)
OregonGhost
Thanks, appreciated
ThePower