0

マクロ関数を (セクション内で) 2 回呼び出すと、次のコンパイル エラーが発生します。

エラー: ラベル "CheckForRMSCustomisationLoop:" セクションで既に宣言されています

label(jump) を 2 回定義しているのでわかりますが、それでよろしいですか?

この問題を回避するにはどうすればよいですか?

マクロを関数に変換する必要がありますか、それとももっと簡単な方法がありますか? 関数に変換すると、パラメーターを渡すことができないため、スタックを使用する必要があります。

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
*/
4

3 に答える 3

1

TestLabel1そうです、ラベルをTestLabel22 回定義しています。

この方法を使用して、ラベル名を一意にすることができます。

!macro Test param1 param2
    !define ID ${__LINE__}
    TestLabel1_${ID}:
        DetailPrint "TestLabel1"
    TestLabel2_${ID}:
        DetailPrint "TestLabel2"
!macroend 

詳細はこちら:

http://nsis.sourceforge.net/Macro_vs_Function#labels

于 2012-12-17T23:20:53.510 に答える
0

これは解決策であり、非常にエレガントでもあるようです:

!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
于 2012-12-18T04:53:53.807 に答える
0
!macro test p1
!define test_ "test${__LINE__}"
IntCmp ${p1} 3 ${test_}double 0
DetailPrint ${p1}
Goto ${test_}end
${test_}double:
IntOp $0 ${p1} * 2
DetailPrint $0
${test_}end:
!undef test_
!macroend

; If the macro is very large and you call it multiple times it might be better to use a function or a macro/function hybrid:
!include util.nsh
!macro testmacroasfunction
Pop $0
IntCmp $0 3 double 0
DetailPrint $0
Goto end
double:
IntOp $0 $0 * 2
DetailPrint $0
end:
!macroend
!macro test2 p1
Push ${p1}
${CallArtificialFunction} testmacroasfunction
!macroend

section
!insertmacro test 2
!insertmacro test 3
!insertmacro test 4

!insertmacro test2 2
!insertmacro test2 3
!insertmacro test2 4
sectionend
于 2012-12-18T19:40:37.687 に答える