We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Button press = Custom code ?

Hello,

Is there a way that I can execute custom code when the user presses a button?

Thanks
Mike
Last edited by MLiss@Cetrus.com on Fri Sep 09, 2016 5:39 pm, edited 1 time in total.
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

I have created a sample installer (attached) and am calling the DLL through a custom action via a button press on the "Folder Dialog"

The DLL code is very simple, here is my DLL Main:

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}


Here is the exported function:

.h file

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the INSTALLCHECKWIN32_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// INSTALLCHECKWIN32_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef INSTALLCHECKWIN32_EXPORTS
#define INSTALLCHECKWIN32_API __declspec(dllexport)
#else
#define INSTALLCHECKWIN32_API __declspec(dllimport)
#endif

INSTALLCHECKWIN32_API int fnInstallCheckWin32(void);



.cpp file:

// InstallCheckWin32.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "InstallCheckWin32.h"

// This is an example of an exported function.
INSTALLCHECKWIN32_API int fnInstallCheckWin32(void)
{
return 42;
}


Here is the error in the log:
MSI (c) (B0:60) [09:35:59:989]: PROPERTY CHANGE: Adding CustomActionData property. Its value is 'InstallCheckWin32.dll?I;PROPERTY;S;fnInstallCheckWin32;'.
Action ended 9:35:59: AI_DATA_SETTER. Return value 1.
MSI (c) (B0:60) [09:35:59:989]: Doing action: CallFunctionFromDLL
Action start 9:35:59: CallFunctionFromDLL.
MSI (c) (B0:B0) [09:35:59:991]: Invoking remote custom action. DLL: C:\Users\mliss\AppData\Local\Temp\MSI6AB3.tmp, Entrypoint: CallStdFcn
MSI (c) (B0!D4) [09:35:59:993]: Product: Your Application -- Error 4157. Failed to load InstallCheckWin32.dll. Error:The specified module could not be found.
Attachments
CustomAction.zip
entire project
(189.92 KiB) Downloaded 472 times
ErrorLog.txt
Error log
(62.33 KiB) Downloaded 445 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Update:

Changed the DLL to a temporary file... now the installer is finding the DLL, but not finding the entry point:

MSI (c) (24:04) [09:47:28:253]: Doing action: AI_DATA_SETTER
Action start 9:47:28: AI_DATA_SETTER.
MSI (c) (24:04) [09:47:28:253]: PROPERTY CHANGE: Adding CustomActionData property. Its value is 'C:\Users\mliss\AppData\Local\Temp\InstallCheckWin32.dll?I;PROPERTY;S;fnInstallCheckWin32;'.
Action ended 9:47:28: AI_DATA_SETTER. Return value 1.
MSI (c) (24:04) [09:47:28:253]: Doing action: CallFunctionFromDLL
Action start 9:47:28: CallFunctionFromDLL.
MSI (c) (24:3C) [09:47:28:255]: Invoking remote custom action. DLL: C:\Users\mliss\AppData\Local\Temp\MSIEB1A.tmp, Entrypoint: CallStdFcn
MSI (c) (24!F0) [09:47:28:259]: Product: Your Application -- Error 4151. Function 'fnInstallCheckWin32' not found in DLL 'C:\Users\mliss\AppData\Local\Temp\InstallCheckWin32.dll'.
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Here is the updated installer that puts the DLL into a temporary directory
Attachments
CustomAction_2.zip
Puts DLL into temp directory, but cannot find entry point
(18.33 KiB) Downloaded 281 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Picture showing DLL in temp directory
FileInTempDir.png
FileInTempDir.png (28.23 KiB) Viewed 10058 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

The entry point is exported as a C++ export according to Dependency walker
Depends.PNG
Depends.PNG (27.44 KiB) Viewed 10058 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

When I use the mangled name "?fnInstallCheckWin32@@YAHXZ" the call succeeds?
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

So upon a little more research.

Here is what I found: Name mangling is the culprit.

I added an exports section to my DLL:
Exports.PNG
Exports.PNG (3.12 KiB) Viewed 10058 times
Ran Dependency walker again:
Depends_AfterExportsAdded.PNG
Depends_AfterExportsAdded.PNG (26.28 KiB) Viewed 10058 times
The installer now loads the DLL and executes the function.

Next problem:
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

When I load the DLL from a C++ program and invoke the function :

HINSTANCE hModule = LoadLibrary(L"C:\\Temp\\InstallCheckWin32\\Debug\\InstallCheckWin32.dll");

test_FUNC pFunc = (test_FUNC)GetProcAddress(hModule, "fnTest");

int nSize = pFunc(L"some string");

FreeLibrary(hModule);

I get the following from my DLL:
Dialog1.PNG
Dialog1.PNG (4.28 KiB) Viewed 10056 times
and
Dialog2.PNG
Dialog2.PNG (10.92 KiB) Viewed 10056 times

However when I run the custom action that invokes the DLL from AdvancedInstaller I do not get anything in the dialog
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Here is my installer project (again) with the text problem
Attachments
CustomAction_TextProblem.zip
(132.94 KiB) Downloaded 407 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Here is what I get when I invoke my DLL with the installer custom action:


Dialog_Inline.PNG
Dialog_Inline.PNG (4.69 KiB) Viewed 10056 times
and
Dialog_Property.PNG
Dialog_Property.PNG (5.12 KiB) Viewed 10056 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

NOTE: I tried this with both a Property and an Inline value, the results are the same for each.

Property:
Value_Property.PNG
Value_Property.PNG (4.48 KiB) Viewed 10056 times
Inline:
Value_Inline.PNG
Value_Inline.PNG (4.1 KiB) Viewed 10056 times
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Last thing...

I have set an edit box to receive the return value of the custom action
ReturnValue.PNG
ReturnValue.PNG (6.18 KiB) Viewed 10056 times

Even though my DLL returns a hard coded value of 42:
ReturnValue_Code.PNG
ReturnValue_Code.PNG (12.61 KiB) Viewed 10056 times
it is not updating
ReturnValue_NotUpdated.PNG
ReturnValue_NotUpdated.PNG (27.61 KiB) Viewed 10056 times
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Button press = Custom code ?

Hello Mike,

I think this happens because you forgot to explicitly specify the calling convention (i.e. __stdcall) in your function signature. Can you please define your function like this:

Code: Select all

INSTALLCHECKWIN32_API int __stdcall fnTest(TCHAR* lpszTest)
rebuild your DLL and test again the scenario?

Also, please add a "Refresh the current dialog" control event as a publish event on your push button to refresh the UI after calling your custom action.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
MLiss@Cetrus.com
Posts: 366
Joined: Wed Dec 30, 2015 5:40 pm

Re: Button press = Custom code ?

Daniel,


this is how my DLL call is specified right now:

extern "C" __declspec(dllexport) int __stdcall IsIPValid(const wchar_t* Param1)

Return to “Building Installers”