External for running one instance on windows

Trevor DeVore trevor at mangomultimedia.com
Sat Jul 16 18:14:59 EDT 2005


Hi people of the list,

I put together an external this morning that you can use to limit your  
application to one running instance on Windows.  It uses a mutex object  
on Windows which you can read about here:

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ 
dllproc/base/using_mutex_objects.asp>

There is a readme with the archive but basically there are two handlers  
you use:

get ewinRegisterApp("My_App_Unique_String")
ewinUnregisterApp

You can ewinRegisterApp("My_App_Unique_String") when your app first  
launches.  If it returns true then there is only one instance of your  
app running.  If it returns false then another app has registered the  
same string (in this case "My_App_Unique_String") and you should quit.

When you quit your app you call ewinUnregisterApp to release the mutex  
object you created with ewinRegisterApp().

Now you may be asking yourself what would happen if your app crashes.   
Would ewinRegisterApp() still return false?  The answer is no, it would  
return true.  Windows knows that the app that created the original  
mutex object has gone the way of all misbehaved software and it will  
gladly give you control of the orphaned mutex object.

Anyway, I've tested this on Win XP so far and it seems to be working  
nicely.  Note that for every time you call ewinRegisterApp() in one app  
you need to call ewinUnregisterApp in order for another app to be able  
to have ewinRegisterApp() return true.  I may fix that, I may not.  It  
doesn't really bother me.

Anyway, you can download it at:

<http://www.mangomultimedia.com/download/revolution/enhancedwin/ 
EnhancedWin.zip>

There is also a command called ewinOpenURL in the external that will  
always do the right thing when trying to open a url or launch an email  
client on Windows.  You may find that useful as well.

If you have any questions or problems let me know.  If you want the  
source code you can have that too.  It was compiled with Visual C++  
.Net.

-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com




More information about the use-livecode mailing list