From: mariusk@idt.unit.no (Marius Kjeldahl)
Newsgroups: bit.listserv.win3-l
Subject: Re: Help: WinExec
Date: 17 Aug 92 18:43:55 GMT
Reply-To: mariusk@idt.unit.no (Marius Kjeldahl)
Organization: Div. of CS & Telematics, Norwegian Institute of Technology
Ath: sigyn.idt.unit.no!mariusk

In article <WIN3-L%92081710512777@UICVM.BITNET>,         $LPAHM0@LUCCPUA.BITNET writes:
|> Hi, folks:
|> 
|> This is going to become more interesting somehow. I have tried to check
|> the "Exclusive" option in PIF file, but it didn't do the work that
|> I want. Instead, Windows alway run the second one(Win.App) first and
|> run the first one(DOS.App) second!!!
|> 
|> My code is like this:
|> 
|> WinExec("File1.pif",SW_SHOW); /* DOS application in pif file */
|> WinExec("File2.exe",SW_SHOW); /* Windows application */
|> 
|> I thought that Windows run them almost samultaniously. That was wrong.
|> Windows always run that Windows application first, no matter where I
|> put that DOS application. This is really wierd.
|> 
|> Any idea, folks?

I had a similar program in a Windows application I am using. The
solution is to start the DOS application and wait for it to finish.
This can not be implemented so "straight forward" as you indicate.
When I posted the question, I`ve got a reply that explained how it
should be done, using the TOOLHELP.DLL (it is included with Windows
3.1).

Im reposting this now..


From wilcox@swarm.wustl.edu Tue Aug 11 15:36:11 1992
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
Organization: Washington University in St. Louis, MO
Cc: 
Status: R

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."
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
Newsgroups: bit.listserv.win3-l