I need to call function from .NET DLL in InstallScript. How can I do it?
Let's start from simple Hello World. Suppose, I created simple class library TestLibrary.dll
using System;
using System.Windows.Forms;
namespace TestLibrary
{
public static class TestClass
{
public static void TestFunction()
{
MessageBox.Show("Hello!");
}
}
}
I don't want to install this DLL on a target box, I only want to run TestFunction()
during installation process, so I just added TestLibrary.dll
in SupportFiles view (I use InstallShield 2013 Professional, Basic MSI Project Type). Then in InstallScript I'm writing prototype for it, loading TestLibrary.dll
and trying to call TestFunction
from it. Something like this:
export prototype TestDllFunction(HWND); //call in Custom Action
prototype TestLibrary.TestFunction();
.......
function TestDllFunction(hMSI)
NUMBER Result;
begin
Result = UseDLL(SUPPORTDIR ^ "TestLibrary.dll");
TestLibrary.TestFunction();
Result = UnUseDLL("TestLibrary.dll");
end;
I've 2 problems here: UseDLL
returns 0 (0 means that DLL was successfully loaded) only if I invoke UseDLL
with hardcoded absolute path to TestLibrary.dll
. And the second problem - suppose, I successfully loaded DLL. How can I invoke my TestFunction
and see a "Hello" messagebox then?