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:
[Files]
Source: c:temp1MyDLL.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~1fooLOCALS~1Tempis-LRL3E.tmpMyDLL.dll.
What am I doing wrong?
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:
When I last worked with InnoSetup it didn't support your scenario directly (calling .NET code from setup).
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.
链接地址: http://www.djcxy.com/p/44510.html