1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Embed DLL in EXE

Discussion in 'Delphi Programming' started by AdminDF, Nov 30, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Actually adding the DLL to your executable is not difficult, just follow the few steps listed below, but you do have a small complication if your target computer's OS is Vista or newer. Vista doesn't allow an application to write to a directory within the Program Files directory without explicit permission from the user (User Access Controls). So GetCurrentDir will not work for you, you'll have to find a different place where you can extract and save the DLL to, such as to the user's APPDATA directory - so you'd have to create a subdirectory for your application, and write the DLL into that subdirectory.[/size]1) Create a text file (with Notepad.exe) and add a line to the text file in the following formatResourceName RCDATA "PathToFile\FileName.DLL"

    so pick a resource name such as MYDLL (you'll use this within your application to find the resource),

    example:

    MYDLL RCDATA "C:\directoryX\directoryY\File.DLL"

    Save the file to the same directory where your source code for your application is, (make sure you save the file as plain ASCII and the extension to the file must be .rc not the normal .txt that Nopepad uses.

    2) From within Delphi, and with your application loaded, use the Project Menu and select Add To Project. Add the resource file you just saved to the project.

    3) Select Project | Build to build your application.

    Now the DLL is part of your executable (you can confirm via the increased file size of your executable)

    (If you make changes to the DLL, and want the updated DLL to be part of the application, make sure you "Build" your application, not just compile - compile does not update the attached resources - while "build" does).

    Now to extract the DLL

    Add the method to extract the DLL to your form's private section


    Code:
    TForm1 = class(TForm)
    ...
    private
      proceducre ExtractResource(const SaveToPath: String);  
      ..
    public
      ..
    end;



    Now add the code:


    Code:
    procedure TForm1.ExtractResource(const SaveToPath: String);
    var
      rs: TResourceStream;
      fs: TFileStream;
    begin
      rs := TResourceStream.Create(hInstance, 'MYDLL', RT_RCDATA);
      try
        fs := TFileStream.Create(SaveToPath+'FileName.DLL', fmCreate);
        try
          fs.CopyFrom(rs, 0);
        finally
          fs.Free;
        end;
      finally
        rs.Free;
      end;
    end;



    Call it like so:


    Code:
    SaveLocation := 'C:\SaveToLocationDirectory\';
    ExtractResource(SaveLocation);
     
  2. whitewarriortr
    Online

    whitewarriortr DF Junior

    Teşekkürler.
    Thanks.
     
  3. gujadoo
    Offline

    gujadoo DF Junior

  4. saedi_mehdi
    Offline

    saedi_mehdi DF Junior

    It was very useful,Tanks
     
  5. ailime0603
    Offline

    ailime0603 DF Junior

    very good idea
     
  6. Rnd0M
    Offline

    Rnd0M DF Member

    RE:

    thank you so much :)
     

Share This Page