Question

I've built some VCL forms in Delphi DLL's which show during the Inno Setup installation. However, it would be much more concise if I could embed these forms into the Inno Setup wizard.

How can I go about doing this?

Was it helpful?

Solution

The simplest way for you will be to create an exported function which will do all the stuff in your library. The necessary minimum for such function is a parameter for the handle of the Inno Setup control into which your form should be embedded. The next necessary thing you need to know for embedding are bounds, but those you can get with the Windows API function call on the library side.

Here is the Delphi part showing the unit with the form from your DLL project:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TEmbeddedForm = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  end;

procedure CreateEmbeddedForm(ParentWnd: HWND); stdcall;

implementation

{$R *.dfm}

{ TEmbeddedForm }

procedure TEmbeddedForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

{ CreateEmbeddedForm }

procedure CreateEmbeddedForm(ParentWnd: HWND); stdcall;
var
  R: TRect;
  Form: TEmbeddedForm;
begin
  Form := TEmbeddedForm.Create(nil);
  Form.ParentWindow := ParentWnd;
  Form.BorderStyle := bsNone;
  GetWindowRect(ParentWnd, R);
  Form.BoundsRect := R;
  Form.Show;
end;

exports
  CreateEmbeddedForm;

end.

And here is the Inno Setup script:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
Source: "MyDLL.dll"; Flags: dontcopy

[Code]
procedure CreateEmbeddedForm(ParentWnd: HWND);
  external 'CreateEmbeddedForm@files:MyDLL.dll stdcall';

procedure InitializeWizard;
var
  CustomPage: TWizardPage;
begin
  CustomPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  CreateEmbeddedForm(CustomPage.Surface.Handle);
end;

Just to note, Inno Setup supports also COM Automation, so the above way is not the only option how to embed an object into the wizard form. However, it's the simplest one.

Oh, and yet one note, which might be good for you to know. If you'd ever need to execute a certain Inno Setup script code from your library, you could do it by making a callback function on the Inno Setup side and passing and executing it on the DLL side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top