dc


{ City } hyderabad
< Country > india
* Profession * software engineer
User No # 46489
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 2
Users Marked my Answers as Wrong # 0
Questions / { dc }
Questions Answers Category Views Company eMail




Answers / { dc }

Question { HP, 11794 }

Hi All,
I have created one MFC Dialog Based application.now if i am
running the application its working fine,instead of closing
he application i minimized the application,if i run the
application again,i am getting the Dialog.

I want to prevent the calling of application multiple times.
please give me the code and let me know in which method i
need to make changes.

Praveer


Answer

A: You need to create a named mutex semaphore when you
start your application. When the second one starts it tries
to get access to the mutex but will fail...


Code:
// app.h
class CYourApp : public CWinApp
{
...

private:
HANDLE hMutex;
};

// app.cpp
BOOL CYourApp::InitInstance()
{
// Create mutex
hMutex = ::CreateMutex(NULL, TRUE, "GlobalMutex");

switch(::GetLastError())
{
case ERROR_SUCCESS:
// Mutex created successfully. There is no instance
running
break;

case ERROR_ALREADY_EXISTS:
// Mutex already exists so there is a running
instance of our app.
return FALSE;

default:
// Failed to create mutex by unknown reason
return FALSE;
}
}

Is This Answer Correct ?    2 Yes 0 No