Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

XelitanMem---embed-DLL-in-EXE

XelitanMem - embed multiple DLL in EXE for Lazarus/FPC

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

XelitanMem - embed DLL in EXE

This library uses https://github.com/Fr0sT-Brutal/Delphi_MemoryModulee Tested on Lazarus 3.8 64 bit.

What is this for?

This allows you to embed any number of DLLs inside your EXE and use them directly from RAM without unpacking to disk. You can even gzip them so the .EXE file is smaller.

Usage example

If you use DLL functions ina static style in your exe:

pascal
function MyFun(const data: PByte; data_size: Cardinal; var width, height: Integer): Integer; cdecl; external 'my_lib.dll';

then you need to change to dynamic style:

pascal
type TMyFun = function(const data: PByte; data_size: Cardinal; var width, height: Integer): Integer; cdecl;

Now instead of using LoadLibrary, GetProcAddress and FreeLibrary you do:

1) Add XelitanMem to uses

2) Add initialization and finalization sections on the bottom of your .pas file:

pascal
initialization
  Load; 

finalization
  UnLoad;

3) Add and customize these 2 functions somwhere in your .pas file:

pascal
var MyFun   : TMyFun   = nil; //put this somewhere global

{$R my_dll.rc}
var lib : TDynLib;
procedure Load;
begin
  try
    lib := DynLib('MY_DLL'); //change name of your DLL here

    MyFun   := DynFun(lib, 'MyFun'); //list all your functions here
  except
  end;
end;

procedure UnLoad;
begin
  DynFree(lib);
end;

4) Create file my_dll.rc, open in a text editor and enter:

pascal
MY_DLL         RCDATA "name_of_my_dll.dll"

Now the best part- you can use as many .rc files as you want or create 1 big .rc file with many DLLs. You can gzip your DLLS and put gzipped DLLS in .rc file:

pascal
MY_DLL         RCDATA "name_of_my_dll.dll.gz"