views:

91

answers:

2

Does anyone know an API function to extract an icon resource from an executable file that's in RAM (inside, say, a MemoryStream)?

All of the icon-extracting functions I've seen so far depend on the executable file being present on disk. I'd like to extract the icon without having to write the exe to a temp file, and then loading the resources from it.

A: 

Hi, if we are talking about taking icon from already build DLL use Reflector

http://www.red-gate.com/products/reflector/

to open the DLL and the just click on the icon with the right mouse button and click Save As also this can be done by code using reflection

Assembly myAssembly = Assembly.Load("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
Stream myStream = myAssembly.GetManifestResourceStream( "MyNamespace.SubFolder.MyImage.bmp" );
Bitmap bmp = new Bitmap( myStream );

Best Regards, Iordan

IordanTanev
I think he specific said that he want to read icons from memory.
gbianchi
+1  A: 

This is never a real problem. Windows has the hard requirement that an executable is a file on disk. You can't start a process otherwise. Since you have to write the file to disk anyway, you never have a problem extracting resources from it with an API that requires a path to a file.

Hans Passant
Thanks; I'll have to bite the bullet on that one.
Dmitry Brant