MSI安装被自定义操作DLL中断

时间:2017-12-08 15:54:39

标签: c++ visual-studio dll windows-installer orca

我使用Visual Studio安装项目来创建MSI。我在Orca中编辑了MSI,以便在首次打开时通过DLL执行自定义操作。当我运行MSI时,msiexec记录以下内容:

MSI (c) (E4:BC) [15:28:14:453]: Doing action: CustomAction1
Action 15:28:14: CustomAction1. 
Action start 15:28:14: CustomAction1.
MSI (c) (E4:BC) [15:28:14:453]: Note: 1: 2235 2:  3: ExtendedType 4: SELECT `Action`,`Type`,`Source`,`Target`, NULL, `ExtendedType` FROM `CustomAction` WHERE `Action` = 'CustomAction1' 
MSI (c) (E4:BC) [15:28:14:453]: Creating MSIHANDLE (13) of type 790542 for thread 3260
MSI (c) (E4:B4) [15:28:14:453]: Invoking remote custom action. DLL: C:\DOCUME~1\USERNA~1\LOCALS~1\Temp\MSIA3.tmp, Entrypoint: SampleFunction
MSI (c) (E4:B4) [15:28:14:453]: Closing MSIHANDLE (13) of type 790542 for thread 3260
Action ended 15:28:14: CustomAction1. Return value 3.
MSI (c) (E4:BC) [15:28:14:468]: Doing action: FatalErrorForm
Action 15:28:14: FatalErrorForm. 
Action start 15:28:14: FatalErrorForm.
MSI (c) (E4:BC) [15:28:14:468]: Note: 1: 2235 2:  3: ExtendedType 4: SELECT `Action`,`Type`,`Source`,`Target`, NULL, `ExtendedType` FROM `CustomAction` WHERE `Action` = 'FatalErrorForm' 

然后,安装程序向导会显示错误消息:The installer was interrupted before MyProduct could be installed. You need to restart the installer to try again.

自定义DLL是用C ++编写的。这是源代码:

MyCustomAction.cpp:

// MyCustomAction.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}

UINT __stdcall SampleFunction(MSIHANDLE hModule)
{
        //This is the function that is called by the MSI
        //It is empty because I just want to check that it can be called without interrupting the installer, then I will add the actual functionality
}

MyCustomAction.def:

; MyCustomAction.def
;
; defines the exported functions which will be available to the MSI engine

LIBRARY      "MyCustomAction" 
DESCRIPTION  'Custom Action DLL'

EXPORTS
    SampleFunction

我还在DLL的附加依赖项中引用了msi.lib。当我目前没有明确告诉它做什么时,为什么自定义操作会中断安装?任何帮助将不胜感激。

更新:

在Orca中,自定义操作位于Binary表中,并且是CustomAction表中的类型1。自定义操作为Immediate,发生在IsolateComponents之后WelcomeForm表中的InstallUISequence之后。

1 个答案:

答案 0 :(得分:0)

您应该更新您的代码和帖子,以表明您实际上正在返回ERROR_SUCCESS。无论是否解决问题,关键是要做到这一点是正确的。如果它没有返回值,则调用序列将失败并出现错误。

由于缺少依赖项,您的Dll可能无法加载。如果您在代码中添加了一个简单的消息框调用,那么至少可以看看代码是否真正开始运行。 C ++将需要运行时支持可能尚未在系统上的Dll。

如果事实证明您对C ++运行时具有依赖性,那么您需要在运行MSI之前安装它们。这是先决条件的选择 - 它生成一个setup.exe来安装依赖项,然后安装你的MSI。