Solved

How to execute calculative prognam for dos?

Posted on 1998-06-10
8
243 Views
Last Modified: 2010-04-01
Dear Sir:

    Three months ago,I wrote three prognams with
TC,suppose their names:a.exe,b.exe,c.exe;now,
I desire  write a menu in vc5 so that I can contract
the three prognams,but, when I use the function "system()",It don't display any result. I think You can help me to solve this difficulty.Thank You!
ps:at best,use a SDI prognam.
                             Youngest
0
Comment
Question by:youngest
  • 4
  • 2
  • 2
8 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1165632
Use CreateProcess, WinExec or ShellExecute to execute them.
0
 

Author Comment

by:youngest
ID: 1165633
Can you explain clearly?

       Thank You!
0
 
LVL 23

Expert Comment

by:chensu
ID: 1165634
Instead of using system("a.exe"), use for example

1.
STARTUPINFO StartupInfo =
{
    sizeof(STARTUPINFO),
    NULL,
    NULL,
    NULL,
    0, 0,
    0, 0,
    0, 0,
    0,
    STARTF_USESHOWWINDOW,
    SW_SHOW,
    0,
    NULL,
    NULL,
    NULL,
    NULL
};

PROCESS_INFORMATION ProcessInformation;

if (!::CreateProcess(NULL,
                     _T("a.exe"),
                     NULL,
                     NULL,
                     TRUE,
                     0,
                     NULL,
                     NULL,
                     &StartupInfo,
                     &ProcessInformation))
{
    LPVOID lpMsgBuf;
    ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                    FORMAT_MESSAGE_FROM_SYSTEM,
                    NULL,
                    ::GetLastError(),
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                    (LPTSTR)&lpMsgBuf,
                    0,
                    NULL);
   
    // Display the string.
    ::AfxMessageBox((LPCTSTR)lpMsgBuf);
   
    // Free the buffer.
    ::LocalFree(lpMsgBuf);
}

2. ::WinExec("a.exe", SW_SHOW);

3. ::ShellExecute(hWnd, NULL, _T("a.exe"), NULL, NULL, SW_SHOWNORMAL);
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 22

Expert Comment

by:nietod
ID: 1165635
Note that this program you are creating in VC will have to be a windows program.  VC5 does not create DOS programs.  (you can create a windows console program, which is in many ways similar to a DOS program.)
0
 
LVL 23

Expert Comment

by:chensu
ID: 1165636
nietod,

youngest told us "Three months ago,I wrote three prognams with
TC". By TC, he meant Turbo C, I guess. He is using Visual C++ to write a Windows program which executes those DOS programs.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165637
yeah, I realized that the DOS programs were written in turbo debugger.   But I was wondering if he might also want this progran to be a DOS program, since (1) the others are and (2) I recall him asking questions about windows programs before.   Probably not, but I just thought it might be helpful.  (I have seen questions like.  I just spent $$ on VC and can't get it to compie my DOS program....)
0
 

Author Comment

by:youngest
ID: 1165638
Thank  You for help,despite I can't understand it.
Because I just learn VC++.I plan to write a pop-up
menu,I can choose the item to execute my prognam,
at best,I desire display the results  in SDI,and can print
it .
0
 
LVL 23

Expert Comment

by:chensu
ID: 1165639
You can use the code I provided directly. Just change the program file name (a.exe).
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

831 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