Recent

Author Topic: Executable into executable  (Read 14355 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #15 on: December 28, 2010, 01:51:28 pm »
The unit should have the following:

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}
{$R embeddedexename.res}

procedure SaveResourceAsFile(const ResName: string; ResType: pchar;
  const FileName: string);
begin
  with TResourceStream.Create(hInstance, ResName, ResType) do
    try
      SaveToFile(FileName);
    finally
      Free;
    end;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  SaveResourceAsFile('embeddedexename', 'EXE', 'embeddedexename.exe');
end;

end.

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #16 on: December 28, 2010, 01:56:35 pm »
Error: unit1.pas(47,1) Error: Can't open resource file "C:\Documents and Settings\sammarco\Desktop\Lazarus Progetti\EsempioXinstaller\embeddedexename.res"
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #17 on: December 28, 2010, 01:58:05 pm »
You should replace "embeddedexename" with you embedded executable name.

You must create the resource file before, with Resources tool.
« Last Edit: December 28, 2010, 02:07:35 pm by typo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #18 on: December 28, 2010, 02:19:53 pm »
How it works? I want to create an installer, so I would need to be the ultimate in flexibility.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #19 on: December 28, 2010, 02:21:51 pm »
The source code of the tool is provided.

It simply creates the resource file. It is up to you make a good usage of it.

Creating an installer or a virus, it is an ethical issue and you need to solve it ethically. Ignoring how to do it will not make you an honest programmer.

Jail is not a good place for programming.
« Last Edit: December 28, 2010, 04:29:36 pm by typo »

 

TinyPortal © 2005-2018