[SDL] Embed SDL.dll in the .exe

Andre de Leiradella leiradella at bigfoot.com
Mon Oct 1 07:32:09 PDT 2007


> Hey,
>  
> If anyone wants to tackle this in Windows, here is what I suggest (thoroughly crazy):
>  
> Write a program that extracts all of the necessary files (.exe, .dll, .png, .etc) from _itself_, then runs the main executable that was extracted.  There you go!  So you'll probably have to write a program that creates such a program.
>  
> Jonny D

I did something similar but didn't like the result... I packed everything into one executable. When run, the executable would decompress all DLLs and load them with LoadLibrary. The problems were:

1) I had to declare all the functions from the DLLs that I was using to be able to call them (since I wasn't linking the app to the import libraries of the DLLs I had to get their addresses with GetProcAddress).
2) Since I was not unpacking another executable, I was having trouble loading the DLLs in the right order. Since the path where they were decompressing was not on the path where Windows looks for DLLs, when I loaded SDL_image.dll, for example, the application stopped complaining it couldn't find SDL.dll. So I had to LoadLibrary them in the right order.

Unpacking another executable along with the DLLs may solve those problems. Since it will be decompressed in the same path as the DLLs, it will automatically find them when run. No need to use LoadLibrary and get their addresses with GetProcAddress, and Windows will be able to find and load them in the right order.

This is easy to do, just write a small executable that reads a ZIP attached to the end of the executable, decompress all its contents somewhere, execute the application (an EXE that was decompressed) and, when the app terminates, cleanup everything.

As I'm in need of such solution, I'll try to code something and release to the list.

Cheers,

Andre



More information about the SDL mailing list