Archive: Calling Function (?) from Main and Uninstall Sections


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

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."

Excellent worked perfectly!!!!


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


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

With kichik's code, you put:
!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."
...outside Sections and Functions. It will work fine then.

-Stu


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 ?


!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