You are here:

C++/executing a '.exe' file in a cpp program

Advertisement


Question
i want to run an exe file 'quiz.exe' from a cpp prgram 'game.cpp'. I referred many examples and tried
process() and system(). but nothing seem to work. please help me friend...
yours
arjun (am i too formal?)  

Answer
Hello Arjun.

To run a program from another program in the Windows operating system, you use the CreateProcess function.

You can read about CreateProcess at http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx

There is an example at:

http://msdn.microsoft.com/en-us/library/ms682512%28VS.85%29.aspx

In that example, the WaitForSingleObject call is optional.

At the bottom of the example is this code:

// Close process and thread handles.
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );

It is good to close those handles when you no longer need them.

I hope that helps you. Post a follow up question if you are still having trouble.

Best regards
Zlatko

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.