-
July 31st, 2013, 06:50 AM
#1
Closing a MFC application from command prompt
Hi,
I have created a MFC dialog based application. Now I want to implement such a functionailty that I will be closing my application through command prompt.
And while closing of my application the ExitInstance() method of my application should get called.
Please guide me with the command which I should put in the command prompt to close my application in such a way.
Thanks in Advance,
Mayank
-
July 31st, 2013, 07:31 AM
#2
Re: Closing a MFC application from command prompt
To gracefully close some GUI Windows application from outside of it one has to PostMessage WM_CLOSE to its main window.
I have no idea, however, how it could be dome from a command prompt.
See http://support.microsoft.com/kb/178893
Victor Nijegorodov
-
July 31st, 2013, 07:35 AM
#3
Re: Closing a MFC application from command prompt
You could write a little console app to send the WM_CLOSE message, or perhaps initiate a DDE conversation that would close other app.
-
July 31st, 2013, 07:41 AM
#4
Re: Closing a MFC application from command prompt
In case you have some application running, no matter it's MFC or not, and run it another time in command prompt, you have two different processes. So, to close some running process by running another one, you have to implement an inter-process communication of some kind, which is not just a command that you can "put in the command prompt."
In one of my apps I had a dedicated thread waiting for a global event to signal. On catching the signal it sent a closing message to main window, so the application could shut down normal way (including ExitInstance). Of course, another application opened the global event object and signaled it. As you can see, here I created an inter-process communication based on system event object shared between the applications. You can replicate the scheme, or come up with your own version of IPC.
Best regards,
Igor
-
July 31st, 2013, 07:41 AM
#5
Re: Closing a MFC application from command prompt
Originally Posted by GCDEF
You could write a little console app to send the WM_CLOSE message, or perhaps initiate a DDE conversation that would close other app.
Sure one could!
But as long as some program would be designed for this goal then it should NOT matter whether such a program would start via command prompt or any other way.
Victor Nijegorodov
-
July 31st, 2013, 07:54 AM
#6
Re: Closing a MFC application from command prompt
Originally Posted by VictorN
Sure one could!
But as long as some program would be designed for this goal then it should NOT matter whether such a program would start via command prompt or any other way.
Thanks To all for your valuable inputs. Well I found this following command which is shutting down my application gracefully from command prompt in Windows 7.
TASKKILL /IM TestApp.exe /T
This is also calling the ExitInstance() method of my application. Still I need to check how much successfull it is.
-
July 31st, 2013, 07:57 AM
#7
Re: Closing a MFC application from command prompt
Originally Posted by VictorN
Sure one could!
But as long as some program would be designed for this goal then it should NOT matter whether such a program would start via command prompt or any other way.
I'm not quite sure what you're saying here, but the OP did say he wrote the app that needs to close. DDE's pretty simple to implement and it's one of several approaches. Seems like there ought to be an easier way, but if there is, I don't know what it is.
-
July 31st, 2013, 08:09 AM
#8
Re: Closing a MFC application from command prompt
Originally Posted by mayank_3103
Thanks To all for your valuable inputs. Well I found this following command which is shutting down my application gracefully from command prompt in Windows 7.
TASKKILL /IM TestApp.exe /T
Wow!
Good to know such a command exists (also in XP, according to http://technet.microsoft.com/en-us/l.../bb491009.aspx
I never knew about this command...
So, we still need to learn!
Originally Posted by GCDEF
I'm not quite sure what you're saying here, but the OP did say he wrote the app that needs to close. DDE's pretty simple to implement and it's one of several approaches. Seems like there ought to be an easier way, but if there is, I don't know what it is.
I was saying exactly what I wrote (however I did not concern DDE):
If we design a program for this purpose then the program has to work independent of the way it will start.
Fortunately, OP has found a solution he needed to use (very simple!) from command prompt!
Victor Nijegorodov
-
July 31st, 2013, 12:58 PM
#9
Re: Closing a MFC application from command prompt
Keep in mind that taskkill may not gracefully close your app, so your ExitInstance() method may not always get called (if taskkill needs to call terminateprocess on your app).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|