Search code examples
installationnsis

Compile Error because I call a Macro twice


When I call a macro function twice (inside a section) I get this compile error:

Error: label "CheckForRMSCustomisationLoop:" already declared in section

I understand its because I am defining a label(jump) twice, is that correct?

How can I avoid this problem?

Do I HAVE to convert the macro to a function or is there an easier way? Because converting to a function means I cant pass parameters I have to use the stack.

Outfile "RequireAdmin.exe"
RequestExecutionLevel admin  ;Require admin rights on NT6+ (When UAC is turned on)
!include LogicLib.nsh

!macro Test param1 param2

    TestLabel1:
        DetailPrint "TestLabel1"
    TestLabel2:
        DetailPrint "TestLabel2"

!macroend

Section

    !insertmacro Test 1 2
    !insertmacro Test 3 4

  IfErrors 0 +2
    MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to write to the registry" IDOK +1
SectionEnd

Function TestFunct # I MISS MY PARAMS :(

    Pop $R9 # represents param2: but actually having param2 is SO MUCH more descriptive
    Pop $R8 

    TestLabel1:
        DetailPrint "TestLabel1"
    TestLabel2:
        DetailPrint "TestLabel2"

FunctionEnd

/* Usage
    Push 1
    Push 2
    Call TestFunct
    Push 3
    Push 4
    Call TestFunct
*/

Solution

  • It appears this is a solution and its pretty elegant too:

    !macro Test param1 param2 uid
        TestLabel1_${uid}:
            DetailPrint "TestLabel1"
        TestLabel2_${uid}:
            DetailPrint "TestLabel2"
    !macroend 
    
    # Usage:
    Section
        !insertmacro Test 1 2 ${__LINE__}
        !insertmacro Test 3 4 ${__LINE__}
    SectionEnd