Jump to content
  • Advertisement
Sign in to follow this  
phil05

How do I make a Win32 application load an external exe file?

This topic is 5462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to click a button on my program that loads an outside program. So... if (dude clicks button) load an external .exe file Any idea?

Share this post


Link to post
Share on other sites
Advertisement
If you're using Windows:

void RunProgram(const char* szPath)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si,sizeof(si));
ZeroMemory(&pi,sizeof(pi));
si.cb = sizeof(si);
CreateProcess(szPath, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

// Don't need handles //
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}

// Example usage:
RunProgram("MyApp.exe");
// Or...
RunProgram("C:\\MyApp.exe");



If its not for windows, you can use system("MyApp.exe");.

Share this post


Link to post
Share on other sites
I remember a MFC book that did this sort of thing.
When you click on a button then it pops up that program.
The WIN32 function it used was WinExec. Look in MSDN
library for more info on the function, its parameters,
etc.

WinExec("notepad.exe", SW_SHOW);

But I think this function outdated. It says to use
CreateProcess, like Evil Steve has done.

-prowst

Share this post


Link to post
Share on other sites
Just a note, don't use WinExec. From MSDN:
Quote:
The WinExec function runs the specified application.

Note This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.


Use CreateProcess and you will be happy.

EDIT: nm, like prowst said.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!