HINSTANCE m_HinstanceCallLogger = ShellExecute( m_WinBase, "open", "../CallLogger/CallLogger.exe", "", "", 0 );
Opening and closing a program programatically
I have a windows application (which does not create a window)
I execute it like this.
How do I close this program (elegantly) when the calling program exits?
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{public: SafeShellExecInfo(const string& file, const string& parameters, const string& directory) : file_(file), parameters_(parameters), directory_(directory), handleValid_(false) { // Prepare the raw structure ZeroMemory(&ShExecInfo,sizeof(SHELLEXECUTEINFO)); ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ; 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; }private: SHELLEXECUTEINFO ShExecInfo; bool handleValid_; const string file_; const string parameters_; const string directory_;};
I am thinking about more of a way to send information like variables from one application to another.
How can I do this withouth using something like winsock?
How can I do this withouth using something like winsock?
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
and
recv would become read_env_variable
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
and
recv would become read_env_variable
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement