Include dll into .exe

General FreeBASIC programming questions.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Include dll into .exe

Post by Provoni »

Hey all,

My program uses zlibwapi.dll. Is there a way to include it with the .exe itself so it doesn't need to be included in the program directory?

Thanks
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Include dll into .exe

Post by MrSwiss »

Nope, sorry, no way for .dll (dynamic link lib) loaded/linked at run time.
Only static lib's are linkable at compile time (included in .exe).
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Include dll into .exe

Post by UEZ »

Provoni wrote:Hey all,

My program uses zlibwapi.dll. Is there a way to include it with the .exe itself so it doesn't need to be included in the program directory?

Thanks
Yes for windows at least, it is possible to embed the DLL into the exe and call it directly from the memory. Check this out: http://www.joachim-bauch.de/tutorials/l ... om-memory/
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Include dll into .exe

Post by srvaldez »

never tried it but apparently it can be done, here's a purebasic solution https://www.purebasic.fr/english/viewto ... dll+binary
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Include dll into .exe

Post by UEZ »

srvaldez wrote:never tried it but apparently it can be done, here's a purebasic solution https://www.purebasic.fr/english/viewto ... dll+binary
Definitely it can be done. I did it using Autoit in several project I made. ;-)
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Include dll into .exe

Post by jj2007 »

I have little doubts about that, see How to convert a dynamic dll to static lib? at SOF.

What is certainly possible (and easy to do) is to include the DLL as an RCDATA resource, and to write it to the executable's folder during the first run. In comparison, the PureBasic version posted above may work for some dlls but is ridiculously complicated.

Btw the easiest solution would be to compile the source as a static lib.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Include dll into .exe

Post by srvaldez »

@jj2007
in the link you provided it seems that they are talking about an import lib and not a static lib
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Include dll into .exe

Post by Provoni »

Thanks for your answers everyone.
UEZ wrote: Definitely it can be done. I did it using Autoit in several project I made. ;-)
Can you give a short run down?
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Include dll into .exe

Post by UEZ »

Provoni wrote:Thanks for your answers everyone.
UEZ wrote: Definitely it can be done. I did it using Autoit in several project I made. ;-)
Can you give a short run down?
What do you need exactly?
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Include dll into .exe

Post by Provoni »

Hey UEZ,

Include a dll into .exe, but if there is not a elegant and simple solution then I will skip it.

Thanks
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Include dll into .exe

Post by UEZ »

Provoni wrote:Hey UEZ,

Include a dll into .exe, but if there is not a elegant and simple solution then I will skip it.

Thanks
Afaik, there is no solution for Freebasic yet unless someone is willing to port it to Freebasic, too. For other languages, e.g. AutoIt, yes. I can provide you a sample code but this will be out of scope for this forum providing non Freebasic code.
SARG
Posts: 1763
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Include dll into .exe

Post by SARG »

Include a dll into .exe, but if there is not a elegant and simple solution then I will skip it.
pefrmdllembed could do the job. However not used/tested.

http://pefrm-units.osdn.jp/pefrmdllembed.html

If you get some difficulty to find an executable I took it from https://www.gtagarage.com/mods/show.php?id=28541 (click on donwload mod)

Don't forget to run your AV on it before executing....
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Include dll into .exe

Post by jj2007 »

srvaldez wrote:@jj2007
in the link you provided it seems that they are talking about an import lib and not a static lib
They are talking about several things, and in a fairly confused way even for SOF standards. Of course, an import lib is useless for OP's problem. Converting a DLL into a real static lib, otoh, is a can of worms. The same applies for the attempt to run the code of a DLL from memory: not foreseen by the OS, so you need some dirty hacks to do that.

The cleanest solution is to include the DLL in the installation package. But then OP might run into licensing problems, I suppose. Is hiding it inside the exe the solution?
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Include dll into .exe

Post by Provoni »

jj2007 wrote: The cleanest solution is to include the DLL in the installation package. But then OP might run into licensing problems, I suppose. Is hiding it inside the exe the solution?
Not a licensing problem. Just want the .exe to be stand alone for worst case scenario.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Include dll into .exe

Post by jj2007 »

Provoni wrote:worst case scenario.
Which is?
Post Reply