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

Intenta de esta manera (Try this way):

Var
 obj: Variant
 va: MyVariableType;
Begin
 //Starting
 ExtractTemporaryFile('MyDll.dll');
 RegisterServer(False, ExpandConstant('{tmp}\MyDll.dll'), False);
 obj := CreateOleObject('MyDll.MyClass');
 //Using
 va := obj.MyFunction();
 //Finishing
 UnregisterServer(False, ExpandConstant('{tmp}\MyDll.dll'), False);
 DeleteFile('{tmp}\MyDll.dll');
End;

Suerte (good luck)


You're trying to import a C-style function from your .NET dll - this doesn't really have anything to do with COM interop. COM interop allows you to activate your .NET objects as COM objects, it doesn't expose them as C/C++ exported functions/types.

If your function doesn't need to return any data, why not make a simple .exe that calls your function and just run that from your setup?

Also: See the innosetup support newsgroups where you might get better support.


Oops, my bad, it's been too long since I've read pascal! So, if you need to get the value then there are a couple of possibilities:

  1. Write the functionality in C/C++ and export the function, that's definitely supported.
  2. Use a Managed C++ dll to shim to your .NET dll, and expose the call as a C interface point (this should work, but it's getting messy)
  3. Use an .exe to store the result of your code in a .INI file or the registry or in a temp file and read the result in the setup code section (this is now properly nasty)

When I last worked with InnoSetup it didn't support your scenario directly (calling .NET code from setup).


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.