Grömlin
4th April 2011 17:40 UTC
Checking if mutex-object exists does not work in a loop
My installer does a mutex check within a loop but the problem is, that if I close the program which created this mutex first the installer still thinks it is running. But it isn't. How can I solve this?
Var loop_count
loop:
IntOp $loop_count $loop_count + 1
Sleep 1000
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex") i .r1 ?e'
Pop $0
StrCmp $0 "0" +3 +1
IntCmp $loop_count 10 +1 loop +1
Quit
Afrow UK
4th April 2011 19:17 UTC
.r1 is $1 not $0.
Stu
Grömlin
4th April 2011 20:02 UTC
Still doesn't work. Calling the mutex-check only once does work as it should, no matter whether the application is running or not. It's only within the loop where the mutex-check returns everytime 183, even if the application does not run anymore.
Afrow UK
4th April 2011 20:11 UTC
Also remove the Pop. The call to CreateMutex isn't putting anything on the stack. It's putting its return value directly into $1.
Stu
Grömlin
4th April 2011 21:29 UTC
Ah, I didn't knew this, thanks. But anyway, the problem still exists and now I think I know why. The System-plugin calls GetLastError (and this call will write to the stack) but If I call CreateMutexA several times, the system still returns the "last" error, even if the last call was successful. Would be that possible?
I tried resetting the last error with System::Call 'kernel32::SetLastError(i 0)' but it didn't work. If I called GetLastError after the Set-call the returned code was 80 even if I didn't called SetLastError.
Do you have any idea what is happening there? Or anybody else?
Anders
4th April 2011 22:09 UTC
Why are you not using OpenMutex?
Also, don't mix dll::FunctionnameA with t type, either use Functionname and t, or FunctionnameA and m
Grömlin
4th April 2011 22:55 UTC
Because I didn't knew it so far. After I googled for OpenMutex I found this page and the solution.
Combined with "kernel32::OpenMutex", "kernel32::CloseHandle" did the trick and my loop is perfectly working now. Thank you very much Anders! :D