What is the best practice for extracting icons?

I created an explorer window that scans directories on boot for file types, etc. when it loads, I use

internal static extern uint ExtractIconEx(string szFileName, uint nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons);

and

internal static unsafe extern int DestroyIcon(IntPtr hIcon);

to scan the currently registered icons, and then I link them to im im files. It works fine on my machine, but when I run it on others, I get a small resource error. so my question is which is better? go the way I am and download them all, or each time I need to list the directory to find the file type and link it.

+3
source share
1 answer

Alternatively, you can do this with system.drawing

var icon = System.Drawing.Icon.ExtractAssociatedIcon(@"c:\xxx\some.file");

(You will need to resize this size for a small shell size)

+1
source

All Articles