-
March 21st, 2002, 12:34 PM
#1
How to run an executable with a MFC program ?
Hi there ,
How can I execute a .exe program with a MFC application . I try with execl() instruction , it compiles perfectly , but wen I run the application , an error occurs . With system("program.exe") instruction , an DOS windows appear and is quite nasty .
If someoane can send me a simple MFC app or another instruction with that can execute a program into a MFC application .
Thanks!
-
March 21st, 2002, 12:43 PM
#2
Re: How to run an executable with a MFC program ?
Look at ShellExecute, CreateProcess.
Do not use System.
regards
Prem
Regards,
Prem
-
March 21st, 2002, 01:05 PM
#3
Re: How to run an executable with a MFC program ?
Like the other person said, ShellExecute should do it:
ShellExecute( GetSafeHwnd(), "open", "C:\\mydir\\myProgram.exe", NULL, NULL, 1 );
or
// This will reply on the Windows ability to open an XLS file
ShellExecute( GetSafeHwnd(), "open", "C:\\mydir\\myFile.xls", NULL, NULL, 1 );
That should get you started.
For more fun, check MSDN and do a search for ShellExecute...
( http://msdn.microsoft.com )
Rock on,
RosinCore
-
March 21st, 2002, 04:21 PM
#4
Re: How to run an executable with a MFC program ?
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if(CreateProcess("c:\\test\\test.exe", // Application name
" example.txt", // Additional application arguments
NULL,
NULL,
FALSE,
CREATE_NO_WINDOW | CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&siStartupInfo,
&piProcessInfo) == FALSE)
// Could not start application
// Wait until application has terminated
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
// Close process and thread handles
::CloseHandle(piProcessInfo.hThread);
::CloseHandle(piProcessInfo.hProcess);
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
March 21st, 2002, 04:39 PM
#5
Re: How to run an executable with a MFC program ?
Use
WinExec("Program.EXE");
Good Luck!
Narayana Murty
Rate this post if it helped you!
-
March 21st, 2002, 04:55 PM
#6
Re: How to run an executable with a MFC program ?
The foll. is an excerpt from MSDN, on why u should not use 'WinExec'.
The WinExec function runs the specified application.
Note This function is provided only for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function.
regards
Prem
Regards,
Prem
-
March 21st, 2002, 05:09 PM
#7
Re: How to run an executable with a MFC program ?
You might be right, if the posted question is exactly looking for the answer of CreateProcess(), but here the question is bit different. so the answer should be WinExec() not CreateProcess() or ShellExecute(). Read the question once again.
Narayana Murty.
-
March 21st, 2002, 05:27 PM
#8
Re: How to run an executable with a MFC program ?
Q: How can I execute a .exe program with a MFC application.
The aim is to execute an application, as the Documetation states,
WinExec should not be used, for all we know it may run in a VDM,
and also the documentation states a 'security' reason when passing file
names with spaces.
As a programmer, u should always look to move forword, not backword.
regards
Prem
Regards,
Prem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
On-Demand Webinars (sponsored)
|