PDA

View Full Version : Custom Action Return Code



jackb86
12-20-2004, 03:34 PM
Answer:
set the functiuon decl to?
LONG WINAPI

I am trying to create a custom action to check for a running application. I have a test dll written in C++ (.NET) and have added it to my project at the "After Initialization" step.

The Action runs however always returns a "Return Value" of 1. I know it is running the code that should return a non-one return value by the dialog boxes and the log file, however it always returns 1 and does nto interrupt the exec of the setup. The C++ code is listed below. I am launching the setup with:
"E:\Development\REMS\1.0\install\InstallShield\REMS\Express\SingleImage\DiskImages\DISK1\setup.exe " "/v /lv C:\Log.log"

The log file shows:
Action start 13:56:42: CheckForOutlook.
MSI (c) (88:64): Creating MSIHANDLE (26) of type 790542 for thread 3684
-- MSI_LOGGING -- SampleFunction3: About to show the true Modal MessageBox.
DEBUG: Error 2835: The control ErrorIcon was not found on dialog SetupError
Internal Error 2835. ErrorIcon, SetupError
DEBUG: Error 2835: The control ErrorIcon was not found on dialog SetupError
Internal Error 2835. ErrorIcon, SetupError
-- MSI_LOGGING -- You clicked NO. Asking the user if they wish to exit...
DEBUG: Error 2835: The control ErrorIcon was not found on dialog SetupError
Internal Error 2835. ErrorIcon, SetupError
-- MSI_LOGGING -- User chose to exit the installation. Returning ERROR_INSTALL_USEREXIT
Action ended 13:57:04: CheckForOutlook. Return value 1.


The code is:

#include "stdafx.h"
#include "MSI_Logging.h"
#include <stdio.h>

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


LONG WINAPI SampleFunction ( MSIHANDLE hModule )
{
LogString(hModule, "About to show the MessageBox.");

// I don't recommend using a MessageBox to get user input, because
// we don't know the parent window handle... but for testing
// purposes, I will use a MessageBox.
MessageBox(NULL, "Hello world. This is a normal windows MessageBox(), and it can easily become hidden behind other setup dialogs.", "CodeProject.com", MB_OK);

// now get some property from the MSI, and write it to the log
TCHAR szBuffer1[MAX_PATH] = {'0'};
TCHAR szBuffer2[MAX_PATH] = {'0'};
DWORD dwLen = MAX_PATH;
MsiGetProperty(hModule, "ProductName", szBuffer1, &dwLen);

// Now write a friendly string out to the logfile.
sprintf(szBuffer2, "Your product name is: %s", szBuffer1);
LogString(hModule, szBuffer2);

return ERROR_SUCCESS;
}



UINT __stdcall SampleFunction2 ( MSIHANDLE hModule )
{
MessageBox(NULL, "Hello world", "CodeProject.com", MB_OK);
return ERROR_SUCCESS;
}



long __stdcall SampleFunction3 ( MSIHANDLE hModule)
{
// this function will correctly use a modal messagebox (which is authored in the MSI as the
// Error Dialog (see msidbDialogAttributesError in msi.chm))
LogString(hModule, "SampleFunction3: About to show the true Modal MessageBox.");
// now show a message box... and use the MB_ICONINFORMATION icon
MsiMessageBox(hModule, "Message 1", MB_OK | MB_ICONINFORMATION);

// now ask the user for input, and use the MB_ICONQUESTION.
if (MsiMessageBox(hModule, "Interrupt setup?", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
LogString(hModule, "You clicked YES. Returning to the setup.");
return ERROR_SUCCESS;
}
else
{
// The user is having a rough day.
// Ask them if they want to exit the installation. Using the MB_ICONSTOP
LogString(hModule, "You clicked NO. Asking the user if they wish to exit...");
if (MsiMessageBox(hModule, "I'm sorry to hear that. Would you like to exit this installation?", MB_YESNO | MB_ICONSTOP) == IDYES)
{
// alright. Send back the error message stating that the user wants to exit.
LogString(hModule, "User chose to exit the installation. Returning ERROR_INSTALL_USEREXIT");
return 99; //ERROR_INSTALL_FAILURE ; //ERROR_INSTALL_USEREXIT;
}
else
{
return ERROR_SUCCESS;
}
}