Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a .NET DLL from an Inno Setup script?

I want to call a function from a .NET DLL (coded in C#) from an Inno Setup script.

I have:

  1. marked the Register for COM interop option in the project properties,
  2. changed the ComVisible setting in the AssemblyInfo.cs file,
  3. added these lines to the ISS script:

[Files]

Source: c:\temp\1\MyDLL.dll; Flags: dontcopy

[Code]

function MyFunction(): string;

external 'MyFunction@files:MyDLL.dll stdcall setuponly';

but I still get the following error:

Runtime Error (at -1:0):

Cannot Import dll:C:\DOCUME~1\foo\LOCALS~1\Temp\is-LRL3E.tmp\MyDLL.dll.

What am I doing wrong?

like image 927
Marek Grzenkowicz Avatar asked Sep 05 '08 10:09

Marek Grzenkowicz


People also ask

What is Inno Setup file?

Inno Setup is a free software script-driven installation system created in Delphi by Jordan Russell. The first version was released in 1997.

What language does Inno Setup use?

Inno Setup's [Code] section uses Pascal (or Pascal Script to be more exact, thanks to TLama), likely because Inno Setup itself is written in Pascal Delphi.

How do I create an inno file?

Go to Menu, Project, then Compile to compile and create the setup file. This will create a complete installer. Run the Setup and your application will be installed correctly. Innosetup offers an awesome alternative to create great looking Installers for free.


1 Answers

I read a little bit more about it - now I can see the difference between importing a C-style function and creating an OLE object.

Something like this would work for me:

[Code]
procedure MyFunction();
var
  oleObject: Variant;
begin
  oleObject := CreateOleObject('MyDLL.MyDLL');

  MsgBox(oleObject.MyFunction, mbInformation, mb_Ok);
end;

but it requires registering the DLL file.

I guess I will have to create a command-line application to call the functions from the DLL.

like image 151
Marek Grzenkowicz Avatar answered Sep 19 '22 01:09

Marek Grzenkowicz