Re: Quesion on mutex
Hi..
This is the test case that i did.In the Application1's InitInstance() i
tried to do a OpenMutex.It returns NULL since that mutex has not being
created for the first time.So i launch the second application.No what i
do is i go to the task manager and end only Application1.Application2
is still running.Now when i again try to start application1,in the
InitInstance() when i try to do a open mutex it should return the
handle of the mutex that is already created..Right?Since i have not
ended Application2 the named mutex should still exist right?But it does
not do that..
What may be the problem..
Regards,
Arun
David Ching wrote:
<sabarad_arun@hotmail.com> wrote in message
news:1152769241.050953.279090@b28g2000cwb.googlegroups.com...
So for this what i did was as follows...
In Application2's InitInstance i used a named mutex as follows.
BOOL Application2::InitInstance()
{
hGlobalMutex = CreateMutex(NULL,FALSE,"NamedMutex");
DWORD dwError = GetLastError();
if ( hGlobalMutex != NULL )
{
if ( dwError == ERROR_ALREADY_EXISTS )
{
return FALSE;
}
}
}
Now how can i get this information in the Application1's InitInstance
that one instance of Application2 is already running?
Application 1 can use OpenMutex() to see if "NamedMutex" was created by
Application 2.
Alternatively, you can use the ToolHelp API's to iterate running processes
to check if Application1.exe is running.
-- David