PDA

View Full Version : Compiling DLLs into an EXE



MarkyD
11-12-2002, 10:39 PM
About time I posted something on these boards. :)

Anyway, if I were to have code to load in a library, have a little play with it, and free the library, such as in the following code:

procedure SomeProc;
type
TMyProc = Function(A,B,C: Integer): Integer;
PMyProc = ^TMyProc;
var
Handle: Cardinal;
Proc: PMyProc;
begin
Handle:=LoadLibrary(PAnsiChar('SomeLib.dll'));
Proc:=GetProcAddress(Handle,PAnsiChar('SomeProc')) ;
//Do stuff with Proc.
FreeLibrary(Handle);
end;

Is there any way I could tell Delphi to compile the DLL "SomeLib.dll" somewhere into my program, so that I just have one executable file to play with rather than having to put up with loadsa DLLs? I suppose I could save it into a resource file and use the $R directive to have Delphi compile it into the program's resources, but then I'd be unable to load it without extracting it and saving it to a seperate file first, which seems somewhat pointlessly complicated. :roll:

I've had a search through the Delphi help file, but could only find stuff about design-time and run-time packages. Google and The Microsoft Programmer's Guide to Windows 95 didn't do that much better either...:(

Cheers. :)

Edit: If it helps, I'm using Delphi 7 Personal Edition.

Sly
11-12-2002, 11:05 PM
To load the DLL, it must exist as a separate file since LoadLibrary only takes a filename as a parameter. It seems the solution to extract the DLL from a resource and save it to a temporary file in the application directory is the best solution. You could extract all the DLLs at application startup and delete them at application shutdown.

Kim Friis
12-12-2002, 01:20 PM
I second that. You cannot load a dll file from memory.

I do know that Borland's midas.dll has a special feature, that if you do not want to include the midas.dll file with you application. Then you can just include a special .dcu file and that takes care of things. BUT that is just because they have the midas.dll file as dcu files also, so you you are not the creater of that dll file, you are out of luck.

MarkyD
12-12-2002, 02:28 PM
Oh well, worth a try I suppose. :)

You could extract all the DLLs at application startup and delete them at application shutdown.
Yeah I guess. I just wanted to do a little tidy up of my application, because its a bit all over the place at the moment...:roll: My only complaint about that way is it just feels a bit sloppy creating and deleting files whenever the program start or ends.

Thanks for the replies anyway. :)

jdsgames
09-02-2003, 01:45 AM
Try PEBundle:
http://www.collakesoftware.com/PEBundle/CSPEBundle.htm

Kim Friis
10-02-2003, 09:30 AM
Wow, that looks brilliant. How the hell do they do that? :-)

Well I can read how they do it, but I still think it is brilliant, especially that type where they don't have to write out to disk. If they can do it, you should be able to also.

MarkyD
10-02-2003, 12:28 PM
Hey cheers. That looks just like what I want. Thanks! :)