Single Instance

Blitz3D Forums/Blitz3D Beginners Area/Single Instance

Wobbly(Posted 2004) [#1]
Is it possible to check for an instance of a BB executable running and prevent another instance of the same program starting i.e. as in screensavers


soja(Posted 2004) [#2]
; .lib "kernel32.dll"
; CreateMutex%(lpMutexAttributes%,bInitialOwner%,lpName$):"CreateMutexA" 
; GetLastError%():"GetLastError"

Const ERROR_ALREADY_EXISTS=183

CreateMutex(0,1,"My Program Instance") ; Mutex accessible to any program

If GetLastError() = ERROR_ALREADY_EXISTS Then
	Print "My program is already running" ; Shutdown
Else
	Print "This is the only instance of My Program" ; OK
EndIf



Wobbly(Posted 2004) [#3]
Many thanks for such a speedy response. I will give this a try ..


jhocking(Posted 2004) [#4]
CreateMutex? GetLastError? Did you just make those commands up, or are they undocumented commands?


Wobbly(Posted 2004) [#5]
Getting error message - Function createmutex not found. Do I have to do something else to access kernal32.dll? I am very new to BB


electronin(Posted 2004) [#6]
The commented bit at the top is a userlib delaration. You need to put it in a file called "C:\program files\Blitz3D\userlibs\kernel32.decls" without the semicolons.


Wobbly(Posted 2004) [#7]
Many thanks people - all working well - just not used to such speedy responses in the Delphi programming world ! BB considerably better :-)


soja(Posted 2004) [#8]
Sorry for not explaining earlier -- I was in a bit of a hurry! (It was "cut and paste" from my code archive.)


Wobbly(Posted 2004) [#9]
No problem - thanks again