Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup failing to import DLL

I'm not having any luck importing a Delphi DLL into Inno Setup (Unicode). The DLL has a simple procedure..

procedure Foo(); stdcall;
begin

end;

exports
  Foo;

The DLL is included in the installer source, and added to the files list:

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

Then, I extract this DLL in the initialization:

function InitializeSetup(): Boolean;
begin
  ExtractTemporaryFile('MyDLL.dll');
end;

And finally, declared this procedure in the script:

function DoFoo(): Bool;
  external '[email protected] stdcall';

However, when I run the setup, I get an error:

Cannot Import dll: <utf8>MyDLL.dll.

What am I doing wrong?

like image 698
Jerry Dodge Avatar asked Dec 04 '22 07:12

Jerry Dodge


2 Answers

Since you haven't used delayed loading in your function import, Inno Setup loader failed to run because it didn't found your library. That's because checks whether function exports are available are performed before the InitializeSetup event is fired and so your library was not yet extracted from the archive.

In your case is adding delayload import option the right way. But you can omit manual extracting and tell the installer to extract the library for you if you add files: prefix before the library file name. This prefix is documented as:

During Setup, a special 'files:' prefix may also be used to instruct Setup to automatically extract one or more DLLs from the [Files] section before loading the first DLL.

The whole import in your case can be then shortened to:

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

[Code]
procedure Foo;
  external 'Foo@files:MyDLL.dll stdcall delayload';
like image 200
TLama Avatar answered Dec 29 '22 00:12

TLama


I found the solution right after posting this question by using delayload on the import...

function DoFoo(): Bool;
  external '[email protected] stdcall delayload';
like image 22
Jerry Dodge Avatar answered Dec 28 '22 23:12

Jerry Dodge