Inno Setup failing to import DLL with "Cannot import dll"
delphi, dll, inno-setup, pascalscript
Solution
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';
Problem
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?