How do I prevent the same executable being executed twice (for example if the player double clicks twice on the icon for the program?
Prevent 2 copies of the same executaable.
BlitzMax Forums/BlitzMax Beginners Area/Prevent 2 copies of the same executaable. This is cool for me too - hows it done? preferbly cross-platform (that is if the mac even lets you)
For windows:
Const ERROR_ALREADY_EXISTS = 183 Extern "win32" Function CreateMutex:Int(lpMutexAttributes :Byte Ptr, bInitialOwner, lpName : Byte Ptr) = "CreateMutexA@12" Function GetLastError:Int() = "GetLastError@0" End Extern Function PreventPrevInstance() Local ret = CreateMutex(Null,Null ,"IAMTHEONLYONE".ToCstring()) If getlasterror () = ERROR_ALREADY_EXISTS Notify "You can only start one copy of this program at the same time. ~nThis copy closes now" End EndIf End Function ' test program PreventPrevInstance() ' keep this dialog open to test Notify "There can be only one..."
Excellent! What about passing the args to the currently-running version? So I could hack it so, e.g., if I click on a ".bmx" file while MaxIDE is already running, it doesn't start a new MaxIDE but the old one loads in the file instead?
I wonder if you could send the args as a DragDrop event.
You might want to have a look at this I've posted in the tutorials too:
http://www.blitzmax.com/Community/posts.php?topic=53709
It *should* work for all 3 systems.
http://www.blitzmax.com/Community/posts.php?topic=53709
It *should* work for all 3 systems.
Thank you, I think this will be perfect.