7

Is there a way to get an associated icon in C# without using any DllImports?

When I use Icon.ExtractAssociatedIcon I don't seem to get the icon for drives, folders, SpecialFolder's in Environment or any files on network attached folders. So is there any other way to get an icon using .NET?

Patrick
  • 17,669
  • 6
  • 70
  • 85
  • This article with code on CodeProject might be of help. [Extract icons from EXE or DLL files](http://www.codeproject.com/KB/cs/IconExtractor.aspx) – Nifle Jun 16 '09 at 07:51
  • If you download his source code he is using DllImport("kernel32"...). I want to be able to use my code on non Windows systems as well (without having to change a whole lot of code with #if-statements). – Patrick Jun 16 '09 at 08:40
  • I doubt there is a portable way to extract icons across os'es – Nifle Jun 16 '09 at 09:23
  • Java is portable, and as far as I know Java can extract all kind of icons, or am I wrong? – Patrick Jun 16 '09 at 09:48

2 Answers2

4

.Net have only one method for extracting associated icons, and you already mentioned about it. Every lib you can find uses pinvokes, because they get icons from windows. So if you need to fully portable icon extraction engine, you must write it by yourself, sadly, but this is the only way (and hide all system specific code inside).

arbiter
  • 9,447
  • 1
  • 32
  • 43
0

Not an answer to your question but might be of use.

You can get most of ms windows icons from this file

$VisualStudiosInstallationDirectory\Common7\VS2008ImageLibrary\VS2008ImageLibrary.zip

Substitute 2008 for 2005 if you still use VS2005

Nifle
  • 11,745
  • 10
  • 75
  • 100