Discussion:
External for running one instance on windows
Trevor DeVore
2005-07-16 22:14:59 UTC
Permalink
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
***@mangomultimedia.com
Mark Wieder
2005-07-17 15:41:32 UTC
Permalink
Trevor-

Thanks for this. I've thought about doing this several times, but my
brain never got past trying to decide whether I wanted to use a mutex
or a critical section, and it always got stuffed onto a back burner.
I'll put this to work right away.
--
-Mark Wieder
***@ahsoftware.net
Trevor DeVore
2005-07-17 19:25:01 UTC
Permalink
Post by Mark Wieder
Trevor-
Thanks for this. I've thought about doing this several times, but my
brain never got past trying to decide whether I wanted to use a mutex
or a critical section, and it always got stuffed onto a back burner.
I'll put this to work right away.
I don't know what a critical section is so it made the decision much
easier :-)
--
Trevor DeVore
Blue Mango Multimedia
***@mangomultimedia.com
Mark Wieder
2005-07-18 17:47:12 UTC
Permalink
Trevor-

Sunday, July 17, 2005, 12:25:01 PM, you wrote:

TD> I don't know what a critical section is so it made the decision much
TD> easier :-)

<g>

As I understand it, they're almost the same thing - mutexes work with
multiple threads in an single application, critical section objects
work with multiple threads in a single process. It doesn't help things
any that "critical section" is also used to refer to the code governed
by a mutex.

Here's a fairly concise, albeit microsoftian, writeup:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/critical_section_objects.asp
--
-Mark Wieder
***@ahsoftware.net
Trevor DeVore
2005-07-19 14:30:33 UTC
Permalink
Post by Mark Wieder
Trevor-
TD> I don't know what a critical section is so it made the decision much
TD> easier :-)
<g>
As I understand it, they're almost the same thing - mutexes work with
multiple threads in an single application, critical section objects
work with multiple threads in a single process. It doesn't help things
any that "critical section" is also used to refer to the code governed
by a mutex.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
dllproc/base/critical_section_objects.asp
Ah, thanks for the info. When I searched for how most window
developers handle having only one instance mutex objects seemed to be
the most popular. I guess this makes sense seeing that mutex applies
to apps and critical sections to a single process. In any case, it
was much easier to implement then I thought it would be.
--
Trevor DeVore
Blue Mango Multimedia
***@mangomultimedia.com
Chris Sheffield
2005-07-18 16:15:52 UTC
Permalink
Hi Trevor,

This is great. I've been looking for a good solution to this problem
for quite some time. I've been using a partial solution with the
EXT.dll, but it doesn't always work.

One question: Will this work on any version of Windows, or is it
specific to, say, 2000/XP?

Chris
Post by Trevor DeVore
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
<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
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.
<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
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------
Trevor DeVore
2005-07-19 14:14:29 UTC
Permalink
Post by Chris Sheffield
Hi Trevor,
This is great. I've been looking for a good solution to this
problem for quite some time. I've been using a partial solution
with the EXT.dll, but it doesn't always work.
One question: Will this work on any version of Windows, or is it
specific to, say, 2000/XP?
This should work back to Windows 95.
--
Trevor DeVore
Blue Mango Multimedia
***@mangomultimedia.com
Lynch, Jonathan
2005-07-18 16:20:51 UTC
Permalink
This external is prolly a bit easier to use than the old way, but...

There is a cross platform method for doing this, which has been
discussed on this group. It has the convenience of checking to make sure
that the first version is running, then if the first instance
communicates back to the second instance that it is running, the second
instance will shut down. It involves the use of ports, which can be a
pain to use.

Just FYI

-----Original Message-----
From: use-revolution-***@lists.runrev.com
[mailto:use-revolution-***@lists.runrev.com] On Behalf Of Chris
Sheffield
Sent: Monday, July 18, 2005 12:16 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows

Hi Trevor,

This is great. I've been looking for a good solution to this problem
for quite some time. I've been using a partial solution with the
EXT.dll, but it doesn't always work.

One question: Will this work on any version of Windows, or is it
specific to, say, 2000/XP?

Chris
Post by Trevor DeVore
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
<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
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.
<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
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------


_______________________________________________
use-revolution mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Chris Sheffield
2005-07-18 16:28:44 UTC
Permalink
I tried that at one time but could never make it work right. Of
course, that was back when I was still kind of new at Rev, so I
probably wasn't doing something right. If Trevor's solution doesn't
work for all versions of Windows, maybe I'll take another stab at
doing it this other way.

Chris
Post by Lynch, Jonathan
This external is prolly a bit easier to use than the old way, but...
There is a cross platform method for doing this, which has been
discussed on this group. It has the convenience of checking to make sure
that the first version is running, then if the first instance
communicates back to the second instance that it is running, the second
instance will shut down. It involves the use of ports, which can be a
pain to use.
Just FYI
-----Original Message-----
Sheffield
Sent: Monday, July 18, 2005 12:16 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows
Hi Trevor,
This is great. I've been looking for a good solution to this problem
for quite some time. I've been using a partial solution with the
EXT.dll, but it doesn't always work.
One question: Will this work on any version of Windows, or is it
specific to, say, 2000/XP?
Chris
Post by Trevor DeVore
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
<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
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.
<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
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------
Lynch, Jonathan
2005-07-18 16:35:32 UTC
Permalink
Once I figured it out (with advice from the more experienced folks
here), it worked great - but it was really a pain to work through. A
convenient to use external like this would make doing this much easier -
it is a great idea!

I was using this for a program that runs in the background, and
autolaunches on startup - thus it was essential that the second instance
verify that the first instance was working. Otherwise, if your first
instance gets hung up for some reason, you might have a hard time
starting a working copy of the program.



-----Original Message-----
From: use-revolution-***@lists.runrev.com
[mailto:use-revolution-***@lists.runrev.com] On Behalf Of Chris
Sheffield
Sent: Monday, July 18, 2005 12:29 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows

I tried that at one time but could never make it work right. Of
course, that was back when I was still kind of new at Rev, so I
probably wasn't doing something right. If Trevor's solution doesn't
work for all versions of Windows, maybe I'll take another stab at
doing it this other way.

Chris
Post by Lynch, Jonathan
This external is prolly a bit easier to use than the old way, but...
There is a cross platform method for doing this, which has been
discussed on this group. It has the convenience of checking to make
sure
that the first version is running, then if the first instance
communicates back to the second instance that it is running, the
second
instance will shut down. It involves the use of ports, which can be a
pain to use.
Just FYI
-----Original Message-----
Sheffield
Sent: Monday, July 18, 2005 12:16 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows
Hi Trevor,
This is great. I've been looking for a good solution to this problem
for quite some time. I've been using a partial solution with the
EXT.dll, but it doesn't always work.
One question: Will this work on any version of Windows, or is it
specific to, say, 2000/XP?
Chris
Post by Trevor DeVore
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
<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
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.
<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
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------


_______________________________________________
use-revolution mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Matthew
2005-07-19 18:35:28 UTC
Permalink
There is another way to check if an instance is running
that will work on all OS. When you start the program you
create a file if it is not already there. If it is there
then you close the program.

I hope this helps.

Sincerely, Matt
Trevor DeVore
2005-07-19 19:24:47 UTC
Permalink
There is another way to check if an instance is running that will
work on all OS. When you start the program you create a file if it
is not already there. If it is there then you close the program.
I hope this helps.
Unfortunately you will run into problems if your application
crashes. The file will stay around and when you try to launch your
app again it thinks it is already running. You can come up with
schemes to work around this but using a mutex is much more reliable
and easier on Windows. On Mac you don't have to worry about multiple
instances for each user. I don't do any Linux development right now
so I can't comment on that.

The file method would work better if Revolution would allow you to
get a lock on a file so that nobody else can access it. I didn't see
a way to do this with open file. If this were the case then I think
you could open the file and lock anybody else out from reading it.
Then if another instance of your app launched and tried to open the
file an error would be returned. If the app crashed then I think the
lock on the file would be released.
--
Trevor DeVore
Blue Mango Multimedia
***@mangomultimedia.com
Lynch, Jonathan
2005-07-20 13:19:21 UTC
Permalink
This would only work if the program deletes that file before it closes -
right?

But, if the program crashes or the power gets cut off and the file is
not deleted, then the next time the program opens, the file will still
be there, and the program will think it is already running, when it
isn't.

-----Original Message-----
From: use-revolution-***@lists.runrev.com
[mailto:use-revolution-***@lists.runrev.com] On Behalf Of Matthew
Sent: Tuesday, July 19, 2005 2:35 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows

There is another way to check if an instance is running
that will work on all OS. When you start the program you
create a file if it is not already there. If it is there
then you close the program.

I hope this helps.

Sincerely, Matt
_______________________________________________
use-revolution mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Jim Bufalini
2005-07-20 13:34:46 UTC
Permalink
Correct. Creating files and depending on your program to delete them, on
exit, is a recipe for disaster. This only works with file locking, and even
then, it depends on the network OS to release the lock, when the program
exits (doesn't always happen, depending on the network, and a combination of
other factors). -Jim

-----Original Message-----
From: use-revolution-***@lists.runrev.com
[mailto:use-revolution-***@lists.runrev.com]On Behalf Of Lynch,
Jonathan
Sent: Wednesday, July 20, 2005 3:19 AM
To: How to use Revolution
Subject: RE: External for running one instance on windows


This would only work if the program deletes that file before it closes -
right?

But, if the program crashes or the power gets cut off and the file is
not deleted, then the next time the program opens, the file will still
be there, and the program will think it is already running, when it
isn't.

-----Original Message-----
From: use-revolution-***@lists.runrev.com
[mailto:use-revolution-***@lists.runrev.com] On Behalf Of Matthew
Sent: Tuesday, July 19, 2005 2:35 PM
To: How to use Revolution
Subject: Re: External for running one instance on windows

There is another way to check if an instance is running
that will work on all OS. When you start the program you
create a file if it is not already there. If it is there
then you close the program.

I hope this helps.

Sincerely, Matt
_______________________________________________
use-revolution mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Trevor DeVore
2005-07-25 18:34:35 UTC
Permalink
Anyone who downloaded the EnhancedWin DLL should download it again. I
had an incorrect configuration option when I compiled the DLL and it
was requiring msvcr71.dll which isn't necessary.

You can download the DLL at :

<http://www.mangomultimedia.com/download/revolution/enhancedwin/
EnhancedWin.zip>
--
Trevor DeVore
Blue Mango Multimedia
***@mangomultimedia.com
Matthew
2005-08-10 19:14:30 UTC
Permalink
On Tue, 19 Jul 2005 12:24:47 -0700
Post by Trevor DeVore
Post by Matthew
There is another way to check if an instance is running
that will
work on all OS. When you start the program you create a
file if it
is not already there. If it is there then you close the
program.
I hope this helps.
Unfortunately you will run into problems if your
application crashes. The file will stay around and when
you try to launch your app again it thinks it is already
running. You can come up with schemes to work around
this but using a mutex is much more reliable and easier
on Windows. On Mac you don't have to worry about
multiple instances for each user. I don't do any Linux
development right now so I can't comment on that.
The file method would work better if Revolution would
allow you to get a lock on a file so that nobody else
can access it. I didn't see a way to do this with open
file. If this were the case then I think you could open
the file and lock anybody else out from reading it.
Then if another instance of your app launched and
tried to open the file an error would be returned. If
the app crashed then I think the lock on the file would
be released.
I don't think that there is a way to lock a file in
revolution but I thought of another solution. Every
half-second or so you could put the current date and time.
Then when you open it up again it would check and see if
it was very recent and if it was it can wait about a
second and do the same check again. Of cource if you were
using a long repeat loop you would have problems but you
could always figure out a different way to do the loop.

Sincerely, Matt

Loading...