mrtech
30th October 2003 21:12 UTC
Calling Function (?) from Main and Uninstall Sections
I use the function below to close my app before the File command in my script and before the Delete command in the unstaller. But I have to completely redefine the function for the uninstaller with a un. prefix, how can i get around this so that I only it defined once, thanks.
Function CloseApp
Pop $R1
loop:
#FindWindow $0 "ThunderRT6FormDC" # All Visual Basic Apps
FindWindow $0 "ThunderRT6Main" $R1
IntCmp $0 0 done
SendMessage $0 ${WM_QUIT} 0 0
SendMessage $0 ${WM_CLOSE} 0 0
SendMessage $0 ${WM_DESTROY} 0 0
Sleep 125
Goto loop
done:
FunctionEnd
Function un.CloseApp
BLAH, BLAH, same as the CloseApp function above
FunctionEnd
kichik
30th October 2003 21:17 UTC
You can put the function in a macro to save the time. For example:
!macro DefineMyFunc UN
Function ${UN}MyFunc
#...
FunctionEnd
!macroend
!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."
mrtech
30th October 2003 22:22 UTC
Excellent worked perfectly!!!!
nduboc
4th June 2004 13:16 UTC
Indeed this is a good solution.
But why does NSIS unforce such a constraint ?
It really complexify write utility function (used in installers as well as uninstaller) without this work-around.
--
Nicolas
fluidz91
17th August 2006 12:41 UTC
Hi,
Kichik, when using "function-in-a-macro" in a section i have errors so i ve found another way : i use "macro-in-a-function" ! like :
macro FUNC_MyFunc UN
#Macro code
>!macroend
>Function MyFunc
!insertmacro FUNC_MyFunc ""
>FunctionEnd
>Function un.MyFunc
!insertmacro FUNC_MyFunc ".un"
>FunctionEnd
>
Then in install/uninstall sections i use :
Call MyFunc / Call un.MyFunc
Afrow UK
17th August 2006 12:46 UTC
With kichik's code, you put:
!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."
...outside Sections and Functions. It will work fine then.
-Stu
fluidz91
17th August 2006 15:49 UTC
This is surely my misusing of NSIS. I thought i had to place code !insertmacro where i need the code to execute. So in this case how do i call the macro in my section ?
Afrow UK
17th August 2006 15:57 UTC
!macro DefineMyFunc UN
Function ${UN}MyFunc
#...
FunctionEnd
!macroend
!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."
Section "My section"
Call MyFunc
SectionEnd
Section "un.My section"
Call un.MyFunc
SectionEnd
-Stu