Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 30th October 2003, 20:12   #1
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
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.
code:
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

mrtech is offline   Reply With Quote
Old 30th October 2003, 20:17   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
You can put the function in a macro to save the time. For example:

code:
!macro DefineMyFunc UN
Function ${UN}MyFunc
#...
FunctionEnd
!macroend

!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 30th October 2003, 21:22   #3
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
Excellent worked perfectly!!!!
mrtech is offline   Reply With Quote
Old 4th June 2004, 12:16   #4
nduboc
Junior Member
 
Join Date: Jun 2004
Posts: 6
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
nduboc is offline   Reply With Quote
Old 17th August 2006, 11:41   #5
fluidz91
Member
 
Join Date: Jun 2006
Location: Paris - FR
Posts: 58
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 :
PHP Code:
!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
fluidz91 is offline   Reply With Quote
Old 17th August 2006, 11:46   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
With kichik's code, you put:
!insertmacro DefineMyFunc ""
!insertmacro DefineMyFunc "un."
...outside Sections and Functions. It will work fine then.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 17th August 2006, 14:49   #7
fluidz91
Member
 
Join Date: Jun 2006
Location: Paris - FR
Posts: 58
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 ?
fluidz91 is offline   Reply With Quote
Old 17th August 2006, 14:57   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
code:
!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

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump