Path: utzoo!attcan!uunet!tank!ncar!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!snorkelwacker!ira.uka.de!fauern!tumuc!lan!rommel From: rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) Newsgroups: comp.windows.ms Subject: spawning under Windows Message-ID: <2568@tuminfo1.lan.informatik.tu-muenchen.dbp.de> Date: 31 May 90 13:41:58 GMT Sender: news@lan.informatik.tu-muenchen.dbp.de Reply-To: rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) Distribution: comp.windows.ms Organization: Inst. fuer Informatik, TU Muenchen, W. Germany Lines: 44 Some time ago I asked for information about controlling spawned child applications under Windows. Spawning applications itself is rather easy if you read the discussion about this topic here last year. What I needed was a "handle" to the child program and a way of at least asking if it still exists. This is an odd situation. MS-DOS has only synchronous spawn (clear) but Windows has only asynchronous spawn (well, better than having only the other type) but nothing like wait() or so. In a program I need to call an external editor (with a text file as an argument) and to read the text file in back after the editor exited WITHOUT user interaction. That means I have to be informed of the childs exit. I did not get any response, this may either be of no interest to others :-( or nothing has done this and some may be interested in a result :-). I played for a while and finally found a way. Well, it uses one undocumented feature but even spawning under Windows itself is not officially documented by Microsoft in the SDK documentation. 1. When you spawn a child program with INT 21 using the Microsoft sample code posted here during the spawn-discussion, you get the instance handle of the child program back in AX from the INT 21. For old applications called using a PIF file (spawn with "PROG.PIF" as executable name) you get the instance handle of WINOLDAP.MOD but this works reliable only if not more than one old app is called. 2. You can test if the application still exists using the GetModuleFilename() call with the handle from 1. The call returns the length of the pathname of the program copied to your buffer or zero, if it does not longer exist. Unexpectedly, the GetModuleUsage() call returns one even if the instance handle given as argument is invalid Now I test for existence of the child app using GetModuleFilename() in a timer callback function after spawning the child and it seems to work reliable even if I call an old application like MicroEMACS as the editor via a PIF file. I HOPE that Windows 3.0 provides an API extension for control of child programs and spawning, the use of INT 21 is SO ugly .... Kai Uwe Rommel Munich rommel@lan.informatik.tu-muenchen.dbp.de