Solved

Single instance...

Posted on 2002-03-06
3
145 Views
Last Modified: 2013-11-20
Hello,
How to have single instace of my application?
Thnaks in advance,
Rani.
0
Comment
Question by:rani2005
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6844873
How To Prevent Multiple copies of a Program Running at the same Time
If you only want to prevent a second instance to run, a mutex object will do the job. It must be placed in the InitInstance method of the CWinApp derived class. As a name for the mutex-object, we chose the name of the application's executable file (CWinApp::m_pszExeName) but you can choose your own unique name.

BOOL COneInstanceApp::InitInstance()
{
     // Standard initialization
     // If you are not using these features and wish to reduce the size
     //  of your final executable, you should remove from the following
     //  the specific initialization routines you do not need.

     HANDLE hSingle;

     hSingle = ::CreateMutex(NULL, TRUE, m_pszExeName);
     if (ERROR_ALREADY_EXISTS == GetLastError()) {
     
          // The system closes the handle automatically when the process
          // terminates
          return FALSE;
     }


     // (...)

}

0
 
LVL 30

Accepted Solution

by:
Axter earned 25 total points
ID: 6844930
See following link for downloadable example:
http://cui.unige.ch/OSG/people/Past/fuentes/Mfc/HowTo_41.html
0
 

Author Comment

by:rani2005
ID: 6845381
Thanks Axter.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now