🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #2876

Re: Waiting for DOS window to finish before continuing in Windows program

#2876
From: Don Wilcox
Date: Tue, 11 Aug 1992 13:35
60 lines
2822 bytes
There is a more elegant way, using the notification routines from toolhelp.dll.
The idea is to ask Windows to notify you whenever any task exits, and then to
check each to see if it is the task you are interested in.  The calls you need
are:
	NotifyRegister	 to inform Windows of your notification proc.
	NotifyUnRegister to clean up.
	WinExec		 to launch your DOS app.  It returns the HINSTANCE
			 of the DOS program.
	TaskFirst	 to find the HTASK for the launched app.  You can
	TaskNext	 check the HINSTANCE from the struct you pass for
			 equality with the one returned form WinExec.

One caveat.  You cannot make any Windows calls from the notification proc
except for PostMessage, so you need to have a Window sitting around that can
be notified of the completion.  The following outline is extracted from working
code:

// Global variables
HTASK hTask;		// The task we was watching.
HWND  hWindow;		// The window to get exit messages.
// Notification procedure
BOOL FAR PASCAL _export WaitForExit(WORD wID, DWORD data) {
	if (wID == NFY_EXITTASK) {
		PostMessage(hWindow, CheckForExitMessage, 0, 0);
	} // if

	return FALSE;
} // WaitForExit

// Processing of CheckForExitMessage within some window.
case CheckForExitMessage:
	if (hTask && !IsTask(hTask)) {
		// The DOS task has exited
		hTask = NULL;
	} // if
	break;

// Launching the DOS app.
	HINSTANCE dosInst;
	TASKENTRY te;

	dosInst = WinExec("MYPROG.EXE", SW_SHOW);
	te.dwSize = sizeof te;	// required
	TaskFirst(&te);
	while (te.hInst != dosInst) {
		TaskNext(&te);
	} // while
	hTask = te.hTask;

That's it.  Don't forget to register the callback, and to unregister when you
are done.

If this is unclear, feel free to send me email.

Don

-- 
Don Wilcox                         | "For I am not ashamed of the Gospel of
Washington University in St. Louis |   Christ, for it is the power of salvation
email: wilcox@swarm.wustl.edu      |   to all who believe."
Technical Details
Message-ID: <9208111335.AA19942@swarm.wustl.edu.wustl.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
Received: from wucs1 (wucs1.wustl.edu) by loke.idt.unit.no with SMTP id AA10677
  (5.65c8/IDA-1.4.4 for <mariusk@idt.unit.no>); Tue, 11 Aug 1992 15:36:01 +0200
Return-Path: <wilcox@swarm.wustl.edu>
Received: from swarm.wustl.edu by wucs1 with SMTP
 (5.65a/1.35); id AA28413; Tue, 11 Aug 92 08:34:53 -0500
Received: by swarm.wustl.edu.wustl.edu (920110.SGI/SMI-4.0)
 id AA19942; Tue, 11 Aug 92 08:35:24 -0500
Date: Tue, 11 Aug 92 08:35:24 -0500
From: wilcox@swarm.wustl.edu (Don Wilcox)
Message-ID: <9208111335.AA19942@swarm.wustl.edu.wustl.edu>
To: mariusk@idt.unit.no
Subject: Re: Waiting for DOS window to finish before continuing in Windows program
Newsgroups: comp.os.ms-windows.programmer.misc
In-Reply-To: <1992Aug11.110759.18519@ugle.unit.no>
Organization: Washington University in St. Louis, MO
Status: R