Single Instance
Blitz3D Forums/Blitz3D Beginners Area/Single Instance
| ||
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 |
| ||
; .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 |
| ||
Many thanks for such a speedy response. I will give this a try .. |
| ||
CreateMutex? GetLastError? Did you just make those commands up, or are they undocumented commands? |
| ||
Getting error message - Function createmutex not found. Do I have to do something else to access kernal32.dll? I am very new to BB |
| ||
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. |
| ||
Many thanks people - all working well - just not used to such speedy responses in the Delphi programming world ! BB considerably better :-) |
| ||
Sorry for not explaining earlier -- I was in a bit of a hurry! (It was "cut and paste" from my code archive.) |
| ||
No problem - thanks again |