Solved

Single instance...

Posted on 2002-03-06
3
153 Views
Last Modified: 2013-11-20
Hello,
How to have single instace of my application?
Thnaks in advance,
Rani.
0
Comment
Question by:rani2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 200
Change owner from userA to server Local Administrators 7 71
either24  challenge 19 105
moto 4g phone enable finger print 4 47
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

733 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