【发布时间】:2014-01-31 10:07:34
【问题描述】:
我需要在 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(),所以我只是在SupportFiles视图中添加了TestLibrary.dll(我使用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 时才返回 0(0 表示 DLL 已成功加载)。第二个问题 - 假设我成功加载了 DLL。我怎样才能调用我的TestFunction 并看到一个“Hello”消息框呢?
【问题讨论】:
标签: .net dll installshield installscript