How to pass MSIHandle to dynamic DLL - Advanced Installer Community
jonipichoni
Posts: 2
Joined: Wed Jul 13, 2016 5:38 pm

How to pass MSIHandle to dynamic DLL

Hello folks,

I am trying to write some extra log from a dll during the installation of an msi.
This is the C++ code of the function that can be called from the custom actions:

Code: Select all

void LogString(MSIHANDLE hInstall, TCHAR* szString)
{
	PMSIHANDLE newHandle = ::MsiCreateRecord(2);
	TCHAR szTemp[MAX_PATH * 2];
	sprintf(szTemp, "-- MSI_LOGGING --   %s", szString); 
	MsiRecordSetString(newHandle, 0, szTemp);
	MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
}
so it can be used:

Code: Select all

UINT __stdcall SampleFunction ( MSIHANDLE hModule )
{
	LogString(hModule, "About to show the MessageBox.");
	....
	return ERROR_SUCCESS;
}
But its throwing errors when executed. So I am not sure how MSIHANDLE gets passed to this custom actions.
custom_action_aip.png
custom_action_aip.png (35.18 KiB) Viewed 4287 times
So my questions are:
1) How MSIHandle gets passed to the DLL custom actions? Is it an implicit arg?
2) How can I pass an MSIHandle and more extra params? Is it possible?

Thanks very much in advnaced.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How to pass MSIHandle to dynamic DLL

Hello and welcome to our forums,

Firstly I want to apologize for my delayed reply. We were a bit busy lately (a new release is approaching here).

Unfortunately our current implementation of the "Call function from standard DLL" custom action type doesn't have support to pass an MSIHANDLE parameter to the called DLL. This improvement is already on our TODO list and it will be available in a future version of Advanced Installer. We will notify you on this thread as soon as the improvement will be out.

Until then, as a workaround, to implicitly pass an MSIHANDLE parameter to your DLL function you can use the "Call function from attached native DLL" custom action type. This custom action type implicitly pass the MSIHANDLE parameter to the called function. However, please note that if you need to pass another parameters to your function then this is not possible. This custom action type can pass to your function only the MSIHANDLE parameter. Any other parameter you want to pass you can save it into an installer property which you can access from directly your function code using the "MsiGetProperty" function.
1) How MSIHandle gets passed to the DLL custom actions? Is it an implicit arg?
Yes, this is an implicit parameter which is passed when using the "Call function from attached native DLL" or "Call function from installed native DLL" action types.
2) How can I pass an MSIHandle and more extra params? Is it possible?
Currently this can be done only by using a "Call function from attached native DLL" or "Call function from installed native DLL" action type. However, please note that this custom action types can pass to your function only the MSIHANDLE parameter. Any other parameter you want to pass you can save it into an installer property which you can access from directly your function code using the "MsiGetProperty" function.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jonipichoni
Posts: 2
Joined: Wed Jul 13, 2016 5:38 pm

Re: How to pass MSIHandle to dynamic DLL

Many thanks. That was what I thought. I will get the properties I need using MSIGetProperty instead of using arg params. Thanks again.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How to pass MSIHandle to dynamic DLL

You're always welcome.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: How to pass MSIHandle to dynamic DLL

Hello,

The issue related to the pass MSIHANDLE parameter using the "Call function from standard DLL" action type was fixed in version 13.2 of Advanced Installer released on October 6th, 2016.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”