Is it possible to compile an image file into a DLL or EXE file?

  • Thread starter Thread starter Mark Denardo
  • Start date Start date
M

Mark Denardo

I have a DLL that I created that contains a reference to an image file on my
hard drive and when I go to use that DLL in another program it complains
that it can't find it. (I'm using a relative path in the DLL). I
understand why it's happening, but instead of referencing a global path or
moving the file to the programs directory where I'm using the DLL, I was
wondering if it's possible to compile the image right into the DLL (or EXE
for that matter)? Is that even possible, or do you always have to reference
media files and such by pointing to them in some local directory that you
package up with the program?

Mark
 
IN your DLL project right click the Project in the Solution Explorer, select
Add, and then select Add Existing Item to browse to your image file.
In Solution Explorer, select the image file you just added, and then press
F4 to display its Properties.
Set the Build Action property to Embedded Resource.

Dim rm AsNew ResourceManager("EsriSamples.PanTool", Me.GetType().Assembly)
m_bitmap = CType(rm.GetObject("Pan_Bmp"), System.Drawing.Bitmap)
 
vbnetdev said:
IN your DLL project right click the Project in the Solution Explorer,
select Add, and then select Add Existing Item to browse to your image
file.
In Solution Explorer, select the image file you just added, and then press
F4 to display its Properties.
Set the Build Action property to Embedded Resource.

Dim rm AsNew ResourceManager("EsriSamples.PanTool", Me.GetType().Assembly)
m_bitmap = CType(rm.GetObject("Pan_Bmp"), System.Drawing.Bitmap)

Keep in mind, while compiling the resource into the dll is useful, it can
become troublesome when you get a large amount of files and want to access
each one. Also, keep in mind, doing it this way increases the assembly for
each resource you include....it would take longer startup times, and a
larger memory footprint (please, someone correct me if I'm wrong here).

HTH,
Mythran
 
You are not wrong. He asked how to do it. Not that it would necessarily be
wise. But it may be necessary for him in his situation.
 
vbnetdev said:
You are not wrong. He asked how to do it. Not that it would necessarily be
wise. But it may be necessary for him in his situation.


Yeah, which is why I posted under your post instead of replying directly
under the op's post. This way, he may follow your example, but "keeping in
mind" my post so he doesn't drown himself before he realizes it :)

Mythran
 
Ok I have the image loaded into the project ("sunset.ico"), and under it's
build properties I have it set to Embedded Resource, but I'm a little
confused as to how I load an embedded file into one of my objects (your code
didn't help me much).

Here's the line of code I'm having trouble with:

Me.Icon = New System.Drawing.Icon(CurDir() + "\..\Images\sunset.ico")

btw, this is an EXE I'm building just to save me a step in testing. And I'm
using VS 2005.

Mark
 
Back
Top