Embedded Resource Id?

  • Thread starter Thread starter Darren Green
  • Start date Start date
D

Darren Green

I have a class project with an icon included and also a .resources file
which also includes an icon. I need the resource Id to allow the host to
extract the icon from the assembly, but cannot work out how to reference
the .resources icon.

For example the ico file in my project has a filename of MyIcon.ico, and
by using ildasm I cane get the resource Id quite easily. The manifest
includes -

..mresource public SQLDTS.MyIcon.ico
{
}


...where SQLDTS is my project namespace.

So I can use the resource id of "SQLDTS.MyIcon.ico" and it works a
treat.

However the .resources file also has an icon with the "name" of "MyIcon"
as set using ResEditor.exe, but looking in the manifest I can only see
this-

..mresource public SQLDTS.MyRes.resources
{
}


How do I reference the individual icon? I have tried various
incarnations of SQLDTS.MyRes.resources.MyIcon and such like without
luck.

How do I get resource Id?

I want the old style resource Id, they all used to be 101!

Cheers
 
Darren,
How do I reference the individual icon? I have tried various
incarnations of SQLDTS.MyRes.resources.MyIcon and such like without
luck.

..resources are read with the ResourceManager class. Something like

new ResourceManager().GetObject("MyIcon")

should do it.



Mattias
 
Hello Darren,

Thanks for your post. As I understand, you want to know how to retrieve the
resources embeded in the .resources file. Please correct me if there is any
misunderstanding. You will need to use the ResourceManager Class to
retrieve the embedded icon. Please refer to the following code snippet:

//--------------code snippet---------------
System.Resources.ResourceManager myManager = new
System.Resources.ResourceManager("SQLDTS.MyRes.resources",
System.Reflection.Assembly.GetCallingAssembly());

System.Drawing.Icon myIcon;
myIcon = (System.Drawing.Icon)myManager.GetObject("MyIcon");
//--------------------end of--------------------------

Please refer to the following MSDN article for detailed information:

Retrieving Resources with the ResourceManager Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskretrievingresourceswithresourcemanager.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thank you both for your replies, but unfortunately I am not using .Net
to read the icon, this is done by an external component beyond my
control. This external component expects what is termed a resource id.

As I described I can embed an icon file and using Ildasm I can confirm
the resource Id of "SQLDTS.MyIcon.ico" and use this quite happily.
Unfortunately I cannot derive the equivalent resource Id if the icon is
inside a resource file. The resource id is very much like if not the
same as the old style resources and they way you could reference them.

This may not be possible to do using resource files, and I do have a
workaround by using an individual icon file, but I thought I'd ask.

Thanks
 
Darren,
Thank you both for your replies, but unfortunately I am not using .Net
to read the icon, this is done by an external component beyond my
control. This external component expects what is termed a resource id.

OK, you're probably talking about an old-style WIn32 icon resource
then.

You can set this with the Application Icon project property in VS.NET,
or with the /win32icon command line compiler option. I believe the
icon resource ID is always 32512 as generated by the C# compiler, but
you can verify that by opening your executable file in VS.NET's
(native) resource editor.

If you want to have muliple icon resources in the executable, you'll
have to create a .RES file with the RC compiler in Platform SDK, and
use the command line compiler and its /win32res option to embed it in
your executable.



Mattias
 
Back
Top