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 'Foo@MyDLL.dll stdcall';

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

Cannot Import dll: <utf8>MyDLL.dll.

What am I doing wrong?


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发布此问题后找到了解决方案...

function DoFoo(): Bool;
  external 'Foo@MyDLL.dll stdcall delayload';
链接地址: http://www.djcxy.com/p/44522.html

上一篇: Inno设置窗口标题已损坏(botva2.dll)

下一篇: Inno安装程序无法导入DLL