Solved

Assembly Icon

Posted on 2004-03-29
7
1,653 Views
Last Modified: 2007-12-19
I need to know the icon of my assembly, i know that he is in my assembly as a resource but i can't find how to use it.

Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.MyApp.1");

I have tryed that because the icon in the assembly as no name and ResHacker show it as the icon n°1...
0
Comment
Question by:virtualblackfox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
eric_duncan earned 500 total points
ID: 10710527
If you are talking about the icon that Windows Explorer uses - the one that is set using the Application Icon property in the Visual Studio .Net IDE - then it is stored as an old Win32 style resource in the PE of the file. Check out the following link for some more information. It talks about using the Windows SHGetFileInfo API to retrieve the icons associated with a particular file:

http://www.codeguru.com/Csharp/Csharp/cs_misc/icons/article.php/c4261/

This link might be useful as well. The sample application in this article shows how to pull Win32 resources in .Net using the res:// protocol, as well as how to add them to an existing .Net assembly:

http://www.codeproject.com/csharp/embedwin32resources.asp

Also, there is an old thread here on experts-exchange that talks about pulling icons out shell32.dll, but the same process should work for your assembly file. The only problem with this approach is that is only pulls the 32x32 icons while SHGetFileInfo allows you to pull the 16x16 ones as well:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20909283.html

Hope this helps!

Eric
0
 
LVL 19

Expert Comment

by:Desp
ID: 10711859
To use the embedded file use the following code:

Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
Stream imageStream = thisAssembly.GetManifestResourceStream("ASSEMBLY.FILENAME");
Bitmap image = new Bitmap(imageStream);

You have to be very careful getting the ASSEMBLY and FILENAME correct when loading resources. For example if you created an assembly called "EmbeddedIcon" and you put your icon (Test.ico) in a "Resources" folder then your string should be "EmbeddedIcon.Resources.Test.ico".

If you are having trouble determining the exact string for loading your resource then use the GetManifestResourceNames() method to see all the resources available in your assembly.
0
 
LVL 2

Expert Comment

by:eric_duncan
ID: 10722697
Thanks for the points! Let me know if you have any more questions.

Eric
0
 

Author Comment

by:virtualblackfox
ID: 10733158
"A request has been made to change the grade"

Accepted, the grade was set because the answer wasen't realy one for my exact problem.
But i haven't stated it correctly.

Using Windows API function is impossible, because i want that my code run both with mono and microsoft frameworks on all platforms (BSD and Windows for Microsoft, Windows and Unixes for Mono)

The only solution is writing my own class who read PE executable format and extract the resource, maybe re-using class Mono/Microsoft use for disasembling / Reflection if they are complete enough to list resource.

Including the icon in both managed and PE Standard resource is still possible but don't seem "pretty" to me.

Again, sorry for not following the Guidelines / Asking badly formulated questions.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question