If the executable statically links to the DLL, i.e. there are no calls to LoadLibrary
, then I don't think there are any mechanisms to pack the DLL into the executable since the DLL load is done by the OS application loader prior to the "main" function being called. The only way around this as far as I'm aware is to put the exe and the dlls into another exe. This wrapper exe unpacks the real exe and dlls into a temporary folder and starts the exe, deleting the files when the exe exits.
If you are calling LoadLibrary/Ex
to load the dll, extract the dll from the exe resources to a file prior to the call to LoadLibrary/Ex
.
The real problem is that the LoadLibrary
function does a lot of fixing up of addresses when the library is loaded and only works when loading from a file.