How can I write a single instance MFC application? Pls Help! 
Author Message
 How can I write a single instance MFC application? Pls Help!



Sat, 25 Oct 2003 16:45:37 GMT  
 How can I write a single instance MFC application? Pls Help!
Alexander,

To prevent a second instance starting you could use a mutex like this:

BOOL CDlgApp::InitInstance()
{
        bool bAlreadyRunning;

        HANDLE hMutexOneInstance = CreateMutex( NULL, TRUE,
                        "YOUR_UNIQUE_GUID_GOES_HERE" );

        bAlreadyRunning = ( GetLastError() == ERROR_ALREADY_EXISTS );

        if ( hMutexOneInstance )
        {
                ReleaseMutex( hMutexOneInstance );
        }

        if ( bAlreadyRunning )
        {
                return FALSE;
        }

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sat, 25 Oct 2003 19:00:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ATL MFC EXE singleton server, single instance application

2. ATL MFC EXE singleton server, single instance application

3. Single instance of MFC dialog based application

4. HELP!! Trying to make single-instance only application

5. HELP!! Trying to make single-instance only application

6. HELP!! Trying to make single-instance only application

7. HELP!! Trying to make single-instance only application

8. Single Application Instance

9. Single instance of application

10. How to have a single application instance executing???

11. Single Instance Application

12. Single instance of a SDI application

 

 
Powered by phpBB® Forum Software