Solved

Calling another stand-alone windows program

Posted on 2004-10-08
10
204 Views
Last Modified: 2010-04-01
Hi, I am trying to code a program which calls another stand-alone visual c++ program. Both of them have separate windows interfaces and execution files. I don't want to copy the necessary part, and want them to work separately. How can I code to call another stand-alone windows program? Thank you for your help in advance.
0
Comment
Question by:Luvu
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 8

Assisted Solution

by:mxjijo
mxjijo earned 50 total points
ID: 12264366
0
 
LVL 30

Expert Comment

by:Axter
ID: 12265762
You can also use system() function call.

system("notepad.exe");

Or you can use WinExec() API function.

WinExec("notepad.exe", SW_SHOW);
0
 
LVL 30

Expert Comment

by:Axter
ID: 12265781
FYI:
A common mistake when using these functions, is forgetting to use double '\\' characters to represent the path seperator.

Example:
system("c:\\windows\\notepad.exe");

system("c:\\mypath\\subpath\\mybatfile.bat");

You need to use double \\ path characters to represent the path seperator for all the functions used to call an executable. (WinExec, system, CreateProcess, etc...)
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:Luvu
ID: 12271966
Thanks for the comments. I am sorry that I haven't explained in detail.

The program I am coding has to be able to not only call the other stand-alone process but also give and take the input and output files. CreateProcess() only executes the other process which doesn't have the input or output files.

Let me explain my problem a little bit more.
For example, I have two separate programs of A and B.
B is a stand-alone program with windows interface and takes a input file and generates a output file. Program A is what I am coding which calls program B. Program A have to be able to call program B with a input file and take a output file from program B. Is there any way I can do this?
0
 
LVL 4

Expert Comment

by:bytta
ID: 12276265
If the input and output files are just command line arguments, you can send them with the system() and CreateProcess() calls
system("c:\\path\\to\\program.exe infile.txt outfile.txt");

Use mxjijo's second link for info on CreateProcess()
0
 
LVL 30

Expert Comment

by:Axter
ID: 12278227
>>Is there any way I can do this?
As long as program A (windows App) is able to take command line options for the input and output file.

Does program 'A' have command line options?
0
 
LVL 8

Expert Comment

by:mxjijo
ID: 12278338

>> As long as program A (windows App) is able to take command line options for the input and output file.
      Why you think that is necessary ?
Why can't prog A have no command line args and create process B with commandline args ?

0
 
LVL 30

Expert Comment

by:Axter
ID: 12279448
Correction:
As long as program 'B' (windows App) is able to take command line options for the input and output file.
Does program 'B' have command line options?


>>Why can't prog A have no command line args and create process B with commandline args ?
Sorry.   I meant to say Program 'B'.  I was referring to the Windows Application.  It sounds like the questioner does not have access to the source code for the windows application, which would be he/she will not be able to use command line options if this windows application does not already have this feature.
0
 
LVL 1

Author Comment

by:Luvu
ID: 12282244
I have the source code of program B. However, it will be the best if I don't have to change program B, since it is a complete stand-alone program.

To use the following line, the program B have to take an input and an ouput file, I think.
system("c:\\path\\to\\program.exe infile.txt outfile.txt");

But, in my case,  program B doesn't take any input or output files directly.
Instead, program B is event-driven program. What I want is to call the functions of file_read(), file_save(), and execute() in program B from program A.

Please let me know how I can do this.
0
 
LVL 30

Accepted Solution

by:
Axter earned 150 total points
ID: 12282873
>>But, in my case,  program B doesn't take any input or output files directly.
>>Instead, program B is event-driven program. What I want is to call the functions of file_read(), file_save(), and execute() in
>>program B from program A.

You're going to have to modify program B for this requirement.

You can do use one of the following methods:
1. Modify program B so that it looks for a file in a specific folder, that will give it commands.
2. Use MapView API functions to send commands to program B
3. Send command via socket to program B

All above methods require modification of program B.  This does not mean that program B will no longer be a standand alone program.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

813 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

13 Experts available now in Live!

Get 1:1 Help Now