我需要从 InstallScript 中的 .NET DLL 调用函数。我该怎么做?
让我们从简单的 Hello World 开始。假设,我创建了简单的类库TestLibrary.dll
using System;
using System.Windows.Forms;
namespace TestLibrary
{
public static class TestClass
{
public static void TestFunction()
{
MessageBox.Show("Hello!");
}
}
}
我不想在目标机器上安装这个 DLL,我只想TestFunction()
在安装过程中运行,所以我只是TestLibrary.dll
在 SupportFiles 视图中添加了(我使用 InstallShield 2013 Professional,Basic MSI Project Type)。然后在 InstallScript 中,我正在为它编写原型,加载TestLibrary.dll
并尝试从中调用TestFunction
。像这样的东西:
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;
我这里有 2 个问题:UseDLL
仅当我UseDLL
使用硬编码的绝对路径调用TestLibrary.dll
. 第二个问题 - 假设我成功加载了 DLL。那么我怎样才能调用我的TestFunction
并看到一个“Hello”消息框呢?