Skip to content
⌘ NSIS Forum Archive

How to call NSIS function from C++ DLL

8 posts

htome#

How to call NSIS function from C++ DLL

Hi everyone,

I need help calling a NSIS function from my C++ DLL. I actually have no clue how to pass the address to the DLL.

Scenario:
In ".oninit", I am displaying a Modal Dlg and I need to pass a pointer to a NSIS function so I can call it from the Dialog.

Is it possible?

NSIS
GetFunctionAddress $R0 MyFunction

How do I pass $R0 to my DLL via System::Call?
System::Call "MyDLL::Show(i $HWNDPARENT, i $R0)" ?????

In C++,
void ShowWelcome(HWND hWnd, void** pCallback); ?????

Please let me know if possible...

Thanks
Anders#
The ShowWelcome function has to follow the NSIS plug-in ABI if you want to use NSIS callback functions and the System plug-in would not be used in this case. Take a look at http://nsis.sourceforge.net/Examples/Plugin/exdll.c the extra parameter pointer has a function used to call back into NSIS: extra->ExecuteCodeSegment(atoi(parameterwithaddress)-1,0);
htome#
Is there any way to use System::Call and not use the NSIS plug-in.

what if I make my dialog modeless and use the System::Get to create a callback? This will cause my dialog to behave as Modal due to the loop requirement for callback.

Like:
System::Get "(i .r0, i .r1) isR0"
Pop $0
System::Call "dll::Show(k r0)"
loop:
StrCmp $R0 "callback1" 0 done
DetailPrint "UseCallback passed ($0, $1) to the callback"
Push 1 # return value of the callback
StrCpy $R0 "" # clear $R0 in case there are no more callback calls
System::Call $0 # tell system to return from the callback
Goto loop
done:
System::Free $0
Anders#
I suppose it might be possible but it is a lot easier to just call ExecuteCodeSegment in your .dll.
htome#
It is not possible. The callback locks everything due to the loop. I don't want to add a message pump there.

I don't want to change my DLL to be a NSIS plugin DLL. There is already too much in there to change it.

Anyway, thank you.
JasonFriday13#
And arguments from the nsis script are "popped" off the stack in the plugin by using popstring() or popint().

Those two points are what makes a .dll into an nsis plugin.

__declspec(dllexport) void Show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters* xp)
{
/* Initialize the stack so we can access it from our DLL using
popstring and pushstring. */
EXDLL_INIT();

/* User code here. */

}
htome#
Well, if no extra work is required for the DLL itself, then this is quite straight forward.
I will give it a try!
Thank you so much for your help!