C++/executing a '.exe' file in a cpp program
Expert: Zlatko - 1/7/2010
Questioni 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?)
AnswerHello 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