mdm
Posts: 3
Joined: Fri Mar 17, 2006 1:15 pm

MessageBoxes in custom actions

In a serial number validation custom action, we presently display a message box using the MessageBox API function (after checking UILevel is appropriate) to inform the user the code is not valid.

The problem with this is that we don't know the parent window, so I pass in NULL, and in some cases, the message box pops up behind the installer.

I came across the function MsiProcessMessage which can be used for logging and displaying message boxes.

I have added these functions to my custom action, but when I call the function, no message box is displayed. The message _is_ written to the log, but not shown to the user.

Here's the code

Code: Select all

void MsiMessage(MSIHANDLE hInstall, INSTALLMESSAGE level, const char* szMessage)
{
	if (strlen(szMessage) == 0)
		return;
	            
	//Create a record with only one field
	PMSIHANDLE hRec = MsiCreateRecord(2);
	
	//Handle problem creating record
	if (hRec == NULL)
		return;	
	
	MsiRecordSetString(hRec, 0, _T("[1]"));
	MsiRecordSetString(hRec, 1, szMessage);
		
	DWORD lCount = 256;
	TCHAR buf[256];
	
	MsiFormatRecord(hInstall, hRec, buf, &lCount); 
	
	MsiProcessMessage(hInstall, level, hRec);
}
I call this using this

Code: Select all

char buf[256];
LoadString(hInstance, IDS_SERIAL_INVALID_MSG, buf, 256);
MsiMessage(hInstall, INSTALLMESSAGE_USER, buf);
I have also tried with INSTALLMESSAGE_ERROR, WARNING and various others without any improvment.

Has anyone else successfully managed to get MsiProcessMessage to display a message box? Alternatively, is there a way to get hold of the window handle of the installer?

As always, any help gratefully recieved!
mat.
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

The custom action that does the serial validation is called on the DoAction control event of the "Next" button. Custom actions on this control event cannot use MsiProcessMessage. See the SDK documentation:

http://msdn.microsoft.com/library/defau ... levent.asp

The easiest solution to your problem is to use the GetForegroundWindow() function to get the handle of the active window. Then use this handle as a parameter for MessageBox().

Hope this helps.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
mdm
Posts: 3
Joined: Fri Mar 17, 2006 1:15 pm

That works! Thanks.

Return to “Common Problems”