View Full Version : createMutex
NewsArchive
01-08-2013, 07:26 AM
Hi Friedrich,
what are the correct Parameter Types for the Windows function
CreateMutex (
http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx )?
I tried *LONG,INT,*STRING (and a few other combinations) with the
Function Parameters 0,0,%MUTEX_NAME%, but I get WinLastError 87 (
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
) very often (but not every time) on WinXP x86 SP2.
Thanks for your help.
Markus
NewsArchive
01-08-2013, 07:27 AM
Markus,
Is there a problem with the "Create Named Mutex..." script function?
Friedrich
NewsArchive
01-08-2013, 07:28 AM
Hi Friedrich,
a) I was not aware of it.
b) It returns every time "504" or "508" as Errorcode and in the given
variable, no matter, how many instances I run.
Screenshot attached.
Markus
NewsArchive
01-08-2013, 07:29 AM
Hi Markus,
See: http://www.lindersoft.com/projects/createcheckmutex.zip
1. Compile and start CreateMutex.sb7
2. Compile and start CheckMutex.sb7
If CreateMutex.exe is active, CheckMutex.exe displays "Application active
(my_mutex_01)".
Otherwise, it displays "Application NOT active (my_mutex_01)".
Friedrich
NewsArchive
01-08-2013, 07:29 AM
Hi Friedrich,
thanks for your suggestion. But your implementation is not atomic.
If I first "detect active application" and then "create named mutex", it
is possible, that between this twi statements an other instance does the
detect activ check and so I have two running instances. It is a race
condition.
If i use createmutex in kernel32.dll directly, I have an atomic
check-and-create operation.
Markus
NewsArchive
01-08-2013, 07:30 AM
Hi Markus,
> If i use createmutex in kernel32.dll directly, I have an atomic
> check-and-create operation.
The "Create Named Mutex..." script function is a direct call to the
CreateMutex KERNEL32 API with the 2nd "bInitialOwner" parameter set to
FALSE.
Friedrich
NewsArchive
01-08-2013, 07:30 AM
> b) It returns every time "504" or "508" as Errorcode and in the
> given variable, no matter, how many instances I run.
BTW, if it does not return 0 here then this is the expected behavior for the
CreateMutex Windows API call.
Friedrich
NewsArchive
01-08-2013, 08:08 AM
Hi Friedrich,
ok, so I can use your create-mutex-function and additional check for
getlasterror?
Set Variable %MUTEX_NAME% to "AIDA SQL Client V11.21 Setup"
Call DLL "kernel32.dll" -- Function "SetLastError" (LONG) (0)
Set Variable %MUTEX% to FUNCTION:Create Named Mutex("%MUTEX_NAME%")
Call DLL "kernel32.dll" -- Function "GetLastError" () ()
Display Message Box "Ergebnis = «%_SB_RETURN%»" -- ""
Markus
NewsArchive
01-08-2013, 08:08 AM
Hi Markus,
> ok, so I can use your create-mutex-function and additional check for
> getlasterror?
In your case, the only possible solution is:
Call DLL "Kernel32.dll" -- Function "CreateMutex" (*LONG,INT,STRING)
(0,0,"my_mutex_01")
Set Variable %CREATEMUTEX_ERRORCODE% to "%_SB_ERRORCODE%"
Set Variable %CREATEMUTEX_RETURN% to "%_SB_RETURN%"
Call DLL "Kernel32.dll" -- Function "GetLastError" () ()
Friedrich
NewsArchive
01-08-2013, 08:09 AM
> I tried *LONG,INT,*STRING (and a few other combinations) with the
I would suggest to use: *LONG,INT,STRING
Friedrich
NewsArchive
01-08-2013, 10:14 AM
Thanks, I will give it a try.
Markus
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.