Closing application using sendmessage
-
Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,
-
Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,
Why don't you send
WM_CLOSE
? See "Terminating Windows-Based Application from Another App". :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Why don't you send
WM_CLOSE
? See "Terminating Windows-Based Application from Another App". :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,
Normal console applications do not have a message loop. It is not message driven. It just starts executing the main function until the main function returns. So you cannot send it a windows message. So if the application is running, it should be either waiting on a wait object or waiting for input or running in a loop. So you need to tell us what exactly is going on here.
«_Superman_»
I love work. It gives me something to do between weekends. -
Normal console applications do not have a message loop. It is not message driven. It just starts executing the main function until the main function returns. So you cannot send it a windows message. So if the application is running, it should be either waiting on a wait object or waiting for input or running in a loop. So you need to tell us what exactly is going on here.
«_Superman_»
I love work. It gives me something to do between weekends. -
That console application acts as a watcher. It will open another application.If that application gets crashed,the watcher will again reinvoke that application.While closing the application,that application will close that watcher too.
OK. Now what I want to know is how the watcher is watching the other application. Does it wait on the process handle? Or is it checking for the process existence in a loop?
«_Superman_»
I love work. It gives me something to do between weekends. -
OK. Now what I want to know is how the watcher is watching the other application. Does it wait on the process handle? Or is it checking for the process existence in a loop?
«_Superman_»
I love work. It gives me something to do between weekends. -
That is not a very good design. This is how I would do it. Start a loop with a flag condition. Use
CreateProcess
or any other API that returns a handle to the newly created process. UseWaitForSingleObject
on the process handle. WhenWaitForSingleObject
returns, useGetExitCodeProcess
on the process handle. In the watched application, you can return an arbitrary value (eg. 15243) for normal shutdown. So ifGetExitCodeProcess
returns the arbitrary value, set the flag so that the control comes out of the loop and the watcher also exits.«_Superman_»
I love work. It gives me something to do between weekends. -
That is not a very good design. This is how I would do it. Start a loop with a flag condition. Use
CreateProcess
or any other API that returns a handle to the newly created process. UseWaitForSingleObject
on the process handle. WhenWaitForSingleObject
returns, useGetExitCodeProcess
on the process handle. In the watched application, you can return an arbitrary value (eg. 15243) for normal shutdown. So ifGetExitCodeProcess
returns the arbitrary value, set the flag so that the control comes out of the loop and the watcher also exits.«_Superman_»
I love work. It gives me something to do between weekends.