Archive: StrCmp and invalid opcode


StrCmp and invalid opcode
Yet again, my broken code or something up with NSIS 2.45?

The code below works fine and no issues.


Function .onInit
;various other stuff

phase2:
;Prevent Multiple Instances
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex123") i .r1 ?e'
Pop $R0
StrCmp $R0 0 phase3
MessageBox MB_OK|MB_ICONEXCLAMATION "The $(^Name) installer is already running." /SD IDOK
${WriteErrorCode} "200" "The $(^Name) installer is already running." ; this function calls Abort

phase3:
;Check min disk space requirements
!ifndef DEVELOPMENT
;more stuff


The code below does NOT work. Soon as one launches the installer, you'll get "Installer corrupted. Invalid opcode"

Function .onInit
;various other stuff

phase2:
;Prevent Multiple Instances
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex123") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +4
MessageBox MB_OK|MB_ICONEXCLAMATION "The $(^Name) installer is already running." /SD IDOK
${WriteErrorCode} "200" "The $(^Name) installer is already running." ; this function calls Abort

phase3:
;Check min disk space requirements
!ifndef DEVELOPMENT
;more stuff


What gives? Why do I need a tagged goto location instead of just using line numbers?

What gives? Why do I need a tagged goto location instead of just using line numbers?
Relative jumps specify the number of INSTRUCTIONS to jump, NOT the number of LINES in your script to be jumped.

This is documented in the "Relative Jumps" section in the manual: http://nsis.sourceforge.net/Docs/Chapter4.html#4.4 (Note also the part where the manual mentions using "macro insertion" and relative jumps)

Perhaps it would be best to avoid using relative jumps for now? They can make script maintenance difficult so I rarely use them.

ah-HA, that would explain it then. Thanks (again).