Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

creating a single instance application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
VooDoo - 31 May 2005 05:41 GMT
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
William DePalo [MVP VC++] - 31 May 2005 06:02 GMT
> 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
VooDoo - 01 Jun 2005 00:13 GMT
> 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
William DePalo [MVP VC++] - 01 Jun 2005 01:16 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.