[英]NSI script : calling one macro from another using insertmacro gives error
我试图在NSI脚本中从另一个调用1宏。 两个宏都有MB_OKCANCEL。 编译时会出现以下错误:
** [exec]错误:函数“”中已声明标签“ abort_inst:”
!include "MUI2.nsh"
OutFile abc.exe
!macro installA
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
ABORT
GoTo lblinstall
lblinstall:
!macroend
!macro uninstallA
MessageBox MB_OKCANCEL "?" IDOK install_A IDCANCEL abort_uninstall
abort_uninstall:
ABORT
install_A:
!insertmacro installA
!macroend
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
!insertmacro installA
${Else}
!insertmacro uninstallA
${EndIf}
FunctionEnd
Section "required" main_section
SectionEnd
请帮忙
(下一次,请确保您的代码没有奇怪的换行符)
插入宏时, !macro
和!macroend
之间的所有代码!macroend
将替换您的!insertmacro
。 因此,您不应该在宏中使用静态标签-您只能插入一次宏(使宏无意义!)。可以使用相对跳转(例如Goto +2
),也可以通过向标签添加参数来使标签动态化,例如:
!macro myMacro param1
${param1}_loop:
MessageBox MB_YESNO "Loop this message?" IDYES ${param1}_loop
# some more code
${param1}_end:
!macroend
但是,由于您没有将任何参数传递给宏,所以为什么不简单地使用函数呢?
Function installA
# your code here
Function
Function uninstallA
# your code here
Call installA
FunctionEnd
通过将一个宏转换为Function可以解决此问题,如@idelberg所建议
同样,只要使用宏,就不能使用静态标签。 静态标签只能在功能或部分中使用一次。 您对宏的使用将转换为以下内容:
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
Abort
Goto lblinstall
lblinstall: # FIRST TIME USE
${Else}
MessageBox MB_OKCANCEL "?" IDOK install_A IDCANCEL abort_uninstall
abort_uninstall:
Abort
install_A:
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
Abort
Goto lblinstall
lblinstall: # SECOND TIME USE
${EndIf}
FunctionEnd
因此,由于lblinstall
标签被使用了两次,因此无法使用。 相反,您可以执行以下操作:
Function installA
MessageBox MB_OKCANCEL "A?" IDOK lblinstall
Abort
lblinstall:
FunctionEnd
Function uninstallA
MessageBox MB_OKCANCEL "?" IDOK install_A
Abort
install_A:
Call installA
FunctionEnd
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
Call installA
${Else}
Call uninstallA
${EndIf}
FunctionEnd
(我还可以自由地从您的示例中删除一些不必要的标签)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.