Solved

Single instance...

Posted on 2002-03-06
3
150 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 61
Shell script to login to remote m/c and execute commands 10 78
haveThree challenge 22 118
firstChar challenge 13 115
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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