Avoid multiple instances...?

BlitzMax Forums/BlitzMax Programming/Avoid multiple instances...?

SLotman(Posted 2011) [#1]
I did this to avoid multiple instances of my game running at the same time on Windows, which does work:

' avoid two instances of the game... at least on windows
?Win32
Extern "Win32"
	Function FindWindow%(func$z,func2$z) = "FindWindowA@8"
End Extern

	Local win%=FindWindow(Null,"WINDOW_TITLE_HERE")
	If (win) Then Print "game already running!"; End
?


Does anyone have an idea how the same could be achieved on Mac?


ImaginaryHuman(Posted 2011) [#2]
In one of the screensaver templates/modules floating around the code archives I remember there was something setting a `Process Lock` so that the process could only run the exe once?


ImaginaryHuman(Posted 2011) [#3]
Other people have done it the quick and dirty way which is to write a file to disk to signify that you're running, then delete it upon exit. (and be careful with accidental exits without deletion). Then detect if the file exists before launching.

Last edited 2011


Grisu(Posted 2011) [#4]
This is what you might be looking for?!
http://www.blitzbasic.com/codearcs/codearcs.php?code=2787


Czar Flavius(Posted 2011) [#5]
What happens if they have an unrelated program that happens to have the same window title?


Zeke(Posted 2011) [#6]
http://www.blitzbasic.com/Community/posts.php?topic=79081


SLotman(Posted 2011) [#7]
Hmmm... so on MAC the OS prevent you from launching a second instance? That's good to know :)