tags:

views:

71

answers:

3

How can I include my programs dependency DLLs inside the EXE file (so I only have to distribute that one file)? I am using C++ so I can't use ILMerge like I usually do for C#, but is there an easier way to automatically do this in Visual Studio?

I know this is possible (thats why installers work), I just need some help being pointed to the best way to this.

Thank you for your time.

+1  A: 

Most installers use a zip file (or something similar) to hold whatever files are needed. When you run the installer, it decompresses the data and puts the individual files where needed (and typically adds registry entries, registers any COM controls it installed, etc.)

Jerry Coffin
+2  A: 

There are many problems with this approach. For one example, see this post from REAL Software. Their “REALbasic” product used to do this and had problems including:

  • When writing the DLLs out at run-time, it would trigger anti-virus warnings.
  • Problems with machines where the user doesn’t have write permissions or is low on disk space.

Their attempt to fix the problem caused more problems, including crashes. Eventually they relented and now distribute DLLs side-by-side with apps.

If you really need a single-EXE deployment, and can’t use an installer for some reason, the reliable way is to static-link all dependencies. This assumes that you have the correct .libs (and not just .libs that link in the DLL).

Nate
+1  A: 

There exist two options, both of which are far from ideal:

  1. write a temporary file somewhere
  2. load the DLL to memory "by hand", i.e. create a memory block, put DLL image to memory, then process relocations and external references.

The downside of the first approach is described above by Nate. Second approach is possible, but is complicated (requires deep knowledge of certain low-level things) and doesn't allow the DLL code to access DLL resources (this is obvious - there's no image of the DLL so the OS doesn't know where to take resources).

One more option usable in some scenarios: create a virtual disk whose contents are stored in your EXE file resources, and load the DLL from there. This is possible using our SolFS product (OS edition), but creation of the virtual disk itself requires use of kernel-mode drivers which must be written to disk before use.

Eugene Mayevski 'EldoS Corp