Limiting an application to single instance...problem? [modified]
-
Dear all, I had one MDI application and I want to limit its execution to single instance. I had tried source code from lots of articles (i.e Newcomer's, Naughter ...Armen...) it will work ...but while closing the second instance it raises an exception ... Abnormal program termination!!! This exception generated from "WinMain" when the "pthread->ExitInstance()" get called... How can I solve this ? I am using Windows XP SP2 .....and VC++ 6.0 Thanks in advance...... -- modified at 5:17 Monday 14th August, 2006
vinsankar
-
Dear all, I had one MDI application and I want to limit its execution to single instance. I had tried source code from lots of articles (i.e Newcomer's, Naughter ...Armen...) it will work ...but while closing the second instance it raises an exception ... Abnormal program termination!!! This exception generated from "WinMain" when the "pthread->ExitInstance()" get called... How can I solve this ? I am using Windows XP SP2 .....and VC++ 6.0 Thanks in advance...... -- modified at 5:17 Monday 14th August, 2006
vinsankar
how you are limiting its instances ?
Prasad Notifier using ATL
-
how you are limiting its instances ?
Prasad Notifier using ATL
-
I tried first link only. But cant get second instance. Can you explain it in detail?
Prasad Notifier using ATL
-
I tried first link only. But cant get second instance. Can you explain it in detail?
Prasad Notifier using ATL
Hi , How will u get second instance? those articles tell u abt preventing the second instance from running when there is already one instance running on ur desktop.... ok.........
vinsankar
-
Hi , How will u get second instance? those articles tell u abt preventing the second instance from running when there is already one instance running on ur desktop.... ok.........
vinsankar
There are no direct APIs or functions to identify which is second instance or third instance and so on. Why do u need second instance? What exactly is the problem u r facing? If something is crashing in the
ExistInstance
in the second time, you have to find out which statement is crashing. It may be because, u r trying to access an un initialized variable there which may get initialized in the first instance asInitInstance
will execute completely in the first instance. But in the second instance you may bypass those initializations and exits after the 'previous instance' checking. Then when control reachesExitInstance
it will crash as what ever u r accessing is not initialized. Just a thought. chk it out. Cheers..Milton KB. -
Hi , How will u get second instance? those articles tell u abt preventing the second instance from running when there is already one instance running on ur desktop.... ok.........
vinsankar
When the first instance starts execution, the very first thing it should do is check for a mutex, if not found it should create one. When the second instance starts, it should check for the mutex, when it finds it it should terminate. Look at the
CreateMutex()
andGetLastError()
functions. I'm not sure where to do this in MFC, but in Win32 these routines are the first to be executed inWinMain()
. Also note all of this should be done before creating/reading any other variables. I have a header file containing all these functions and a few more like handling Command line paramaters, and handling MultiUser/MultiDesktop environments. (A modified combination of CP examples). If you like I will send it to you. -
There are no direct APIs or functions to identify which is second instance or third instance and so on. Why do u need second instance? What exactly is the problem u r facing? If something is crashing in the
ExistInstance
in the second time, you have to find out which statement is crashing. It may be because, u r trying to access an un initialized variable there which may get initialized in the first instance asInitInstance
will execute completely in the first instance. But in the second instance you may bypass those initializations and exits after the 'previous instance' checking. Then when control reachesExitInstance
it will crash as what ever u r accessing is not initialized. Just a thought. chk it out. Cheers..Milton KB.Hi, Sorry....... I don't need the second instance......I want to prevent all other instances while one is there.. then..... I fix it ..... I made a mistake in the "return statement" after finding the previous instance of that program in the 'InitInstance()' of my App class. I was written like this... BOOL CMyApp::InitInstance() { if(IsthereApreviousInstance(....GUID)) { AfxMessageBox("Already one Instance"); return FALSE; // This is wrong } } The above code will work but an exception will raised... So I put it like this.... exit(0); // in place of "return FALSE" Ok.............Thanks....to all
vinsankar
-
When the first instance starts execution, the very first thing it should do is check for a mutex, if not found it should create one. When the second instance starts, it should check for the mutex, when it finds it it should terminate. Look at the
CreateMutex()
andGetLastError()
functions. I'm not sure where to do this in MFC, but in Win32 these routines are the first to be executed inWinMain()
. Also note all of this should be done before creating/reading any other variables. I have a header file containing all these functions and a few more like handling Command line paramaters, and handling MultiUser/MultiDesktop environments. (A modified combination of CP examples). If you like I will send it to you.Hi, I solve it .... See my previous message.... Thanks.... -- modified at 11:31 Monday 14th August, 2006
vinsankar
-
Hi , How will u get second instance? those articles tell u abt preventing the second instance from running when there is already one instance running on ur desktop.... ok.........
vinsankar
Vinod A Sankaranarayanan wrote:
How will u get second instance?
that's why I wanted you to explain in detail. Anyway you solve your problem, and shared,too.Thats good.
Prasad Notifier using ATL