• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Single instance...

Hello,
How to have single instace of my application?
Thnaks in advance,
Rani.
0
rani2005
Asked:
rani2005
  • 2
1 Solution
 
AxterCommented:
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
 
AxterCommented:
See following link for downloadable example:
http://cui.unige.ch/OSG/people/Past/fuentes/Mfc/HowTo_41.html
0
 
rani2005Author Commented:
Thanks Axter.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now