Navigation

Search

Categories

On this page

Using Assembly Resources

Archive

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 12
This Year: 0
This Month: 0
This Week: 0
Comments: 0

Sign In

 Tuesday, May 22, 2007
Tuesday, May 22, 2007 1:33:40 PM UTC ( )
In the Pocket PC Controls.com Color Picker control their is an embedded bitmap called 'palette.bmp' used for the drop down color selector. Due to the source code being available to clients, it was not acceptable to hard wire the name of the resource which would include the namespace as the source code may be inserted into projects with namespaces other than PPCC.

palette.bmp

The palette.bmp was added to the project inside a project folder called 'resources' and the build action for that file set as 'Embedded Resource'. When compiled, this resource is embedded into the assembly saving the need for adiditional external files.

Rather than using the fully qualified name for the image ie: 'PPCC.resources.palette.bmp', I have simply searched through all available resources to find the 'palette' bitmap.


System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string[] s = asm.GetManifestResourceNames(); // extract names of
all embedded resources

for (int i = 0; i <= s.GetUpperBound(0); i++) // wind through all available resources
  if (s[i].IndexOf("palette") > 0) // if we find the one we want
    _ColorBitmap = new Bitmap(asm.GetManifestResourceStream(s[i])); // assign that resource for use into a local variable



If you are happy to hard wire the resource name, you could always use ILDASM.exe after compilation to find the fully qualified name of the embedded resource, simply double click on the MANIFEST entry. ILDASM.exe is installed with Visual Studio (C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin) and is an excellent tool to have a look at what is going on inside your compiled IL assemblies, it has been a great tool for me over the years.