Solved

WinExec running in parallel?

Posted on 1997-03-25
1
323 Views
Last Modified: 2013-12-03
I need to run a small DOS application in my Win 3.1 c++ program(MS c++ 1.52).  I'm using WinExec to do this.

My problem is that the line following the WinExec is an if/then statement that relies on a file that the DOS program might or might now create.  IF the DOS program created the file it does one thing, else another.

What it seems to be doing is running both my program and the DOS application in parallel(Win 3.1 definition of parallel:)).  I mean, it seems to be getting past the if/then statement before the DOS application has time to finish and write its output file.

Is there any way to stop the swapping of resources in windows so it only runs the DOS application?  So it runs lineraly?  I've tried several things including a pif file for my DOS application with priorities set to max(10000).

Thanks for any ideas!
0
Comment
Question by:mojo666
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1334219
There is no standard way to do so. However, you can use the following code that I used it for the similar purpose. It works fine.

// You should set the PIF to allow DOS programs background running.
::WinExec("ATTRIB c:\\windows\\*.*", SW_MINIMIZE);

// wait until the DOS program ends
while (::FindWindow("tty", "ATTRIB.EXE") != NULL ||  // for Windows 95
       ::FindWindow("tty", "ATTRIB") != NULL)        // for Windows 3.x
{
    // yield the control to let DOS run
    MSG msg;
    while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
    }
}

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now