creating a single instance application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, is there a way to ensure an application will run a single instance (for
example, like word that opens each document in a different word programm) via
mfc features or do i have to code it myself. i did that once by having my
application reserve a socket, but this is very not elegant. i dont want to
use system registry or temp files since an abnormal termination may leave
trash files that may not allow the program to run in following calls
 
VooDoo said:
hi, is there a way to ensure an application will run a single instance
(for
example, like word that opens each document in a different word programm)
via
mfc features or do i have to code it myself.

Mostly, you have to do it yourself. One technique is discussed here:

http://support.microsoft.com/kb/q243953/

Just by the way, Word takes advantage of the file associations maintained by
the shell (Explorer).

Files with .doc extensions are associated with winword.exe, so if winword is
not already active, the shell will run it and pass the file name as an
argument.

Winword also supports DDE, and if the shell finds that the application is
already running, it sends a DDE message to the active instance which opens
the document specified in the message in a new window.

Regards,
Will
 
Mostly, you have to do it yourself. One technique is discussed here:

http://support.microsoft.com/kb/q243953/


tnx, that article is in fact about what i was looking for, tough i have not
seen it yet in detail to see how it does it, so i can not tell if i'll like
it or not
Just by the way, Word takes advantage of the file associations maintained by
the shell (Explorer).

Files with .doc extensions are associated with winword.exe, so if winword is
not already active, the shell will run it and pass the file name as an
argument.


hmm.. i should have said "for example, not like word (...)" which in fact
opens a different instance for each document
 
VooDoo said:
hmm.. i should have said "for example, not like word (...)" which in fact
opens a different instance for each document

Hmm, not here. It all depends on how you run the subsequent instances.

I just clicked two different .doc files listed in an Explorer window. Both
documents end up being opened by the same instance of winword.exe (from
Office 2003) as the shell sends a DDE message to open the second instance.

Note that even if you follow the advice in the article, for a short time
there will be multiple instances of your executable running. Each subsequent
instance detects the presence of the first and exits. If you have a document
centric application which might need to open another document, it needs to
follow the shell's example and send a "message" to the first instance to
open it. Of course, you don't have to use DDE.

But the point is that the operating system does not a priori prevent
subsequent instances from being launched in the first place.

Regards,
Will
 
Back
Top