There's several ways to do this, here is one (DLL) that works fine on Win9x/NT/2K/XP. The SetMyHook(HWND my_window, HWND subclassed_window) function subclasses the 'subclassed_window' in another process and PostMessage to 'my_window' when it's destroyed. ReleaseMyHook() unsubclasses it.
Exactly why I wait for the Window to close instead of the process. I have noticed that when this window is closed the process is still running. This is why I watch for the window to close, then use terminate process on the running process.
I would change the code of the application, but it is a vendor application that they don't allow changes to.
It doesn't until you reboot the machine. It is a Java Applet using the MVM to run. It opens a port that I need to be closed and reopened every time, but this port is locked as long as the process it running.
What doesn't work is the WaitForSingleObject because it is waiting on a process that doesn't quit. I need a way to find out when the window is closed so that the process can be terminated through TerminateProcess.