Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a process whose main window is then embedded in the calling process' main window by removing the window border, MoveWindow, and SetParent.

I can use TerminateProcess to close the process of the embedded window when the calling process is closed properly, but if the calling process crashes with a "this program has stopped working" Windows message, the child window's process will still be running invisibly in the background eating up resources.

The only way to close the process is by closing it manually in the processes tab of the task manager, Any way to fix this so that everything closes properly even during a crash?

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Oct-14 14:28pm    
For a software developer, strictly speaking, there is no such thing as "crash". What exactly happens and why? Your task is prevent anything which can be called "crashing" (even it there are, for example, exceptions), not handling "crashes". Or it that process not yours? Them why?
Why do you have two different processes at all? What are they doing and why? Also looks like a bad sign to me...
—SA

1 solution

Something you could consider doing, is to implement a regular checking mechanism. The child process would check if the HWND of its parent is a valid HWND. You could set a timer that fired as often as required.

You could use something like the following:
C++
case WM_TIMER:
{
    UINT_PTR wTimerId = wParam;
    switch (wTimerId)
    {
        case checkIfParentAliveTimerId:
        {
            HWND parent = GetParent(hwnd);
            if (IsWindow(parent) == false)
            {
                // parent handle doesn't point to a valid window.
                // initiate clean-up and exit here
            }
        }
        break;
    }
}
return 0;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900