Jump to content
  • Advertisement
Sign in to follow this  

Opening and closing a program programatically

This topic is 4873 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 have a windows application (which does not create a window) I execute it like this.
   HINSTANCE m_HinstanceCallLogger = ShellExecute( m_WinBase, "open", "../CallLogger/CallLogger.exe", "", "", 0 );

How do I close this program (elegantly) when the calling program exits?

Share this post

Link to post
Share on other sites
You'll need to use ShellExecuteEx, and the use WaitForSingleObject with a timeout. See below for some sample code which could be used to poll the application for running status. This is fairly inefficient because of the 0 timeout but it should be simple to modify.

class SafeShellExecInfo
SafeShellExecInfo(const string& file, const string& parameters, const string& directory)
: file_(file), parameters_(parameters), directory_(directory), handleValid_(false)
// Prepare the raw structure
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.hwnd = NULL; // no parent window
ShExecInfo.lpVerb = NULL; // not trying to "open" a file
ShExecInfo.lpFile = file_.c_str(); // set the file to execute
ShExecInfo.lpParameters = parameters_.c_str(); // set the parameters to the executable
ShExecInfo.lpDirectory = directory_.c_str(); // set the working directory
ShExecInfo.nShow = SW_HIDE; // don't give child processes windows
ShExecInfo.hInstApp = NULL; // don't care about this value

void shellExecute()
ShellExecuteEx( &ShExecInfo ); // start the process
handleValid_ = true;

bool isStarted()
return handleValid_; //

bool isRunning()
assert(handleValid_ == true);
return WaitForSingleObject(ShExecInfo.hProcess,0) == WAIT_TIMEOUT;

bool handleValid_;
const string file_;
const string parameters_;
const string directory_;

Share this post

Link to post
Share on other sites
Using a registry key is basically the same thing as using a file.

Memory mapping seems to somplicated for what I am trying to do.

I was thinking of something as simple as send and recv without actually needing all that winsock code.

Isnt there a way to set envrionment veriables or something? That way I could transfer data easily without too much code.

send would become set_env_variable
recv would become read_env_variable

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!