Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Nov 30, 2013.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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
    Offline

    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

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block