afkmarc afkmarc - 3 months ago 12
C++ Question

Callback for running an external application in C++

I'm working on a Kinect v2 application that at some point execute an external Unity mini game that works with Kinect v2 as well. I'm using

ShellExecute
function but I'm not sure how to implement a callback that notify the main application once the Unity application has been closed. I need it because I want to pause the Kinect manager in the main application once Unity is running its own one (otherwise you can imagine two Kinect managers will run at the same time). The code right now looks like:

if (Button->getTag() == "something")
{
Button->SetActive(false);

// TODO Pause Kinect manager
ShellExecute(nullptr,L"open",L"UnityApplication.exe",nullptr,nullptr,SW_SHOWNORMAL);

// TODO to know once Unity Applications has been closed
// TODO resume Kinect manager
}

Answer

Use ShellExecuteEx instead of ShellExecute, passing the flag SEE_MASK_NOCLOSEPROCESS in the fMask field of the SHELLEXECUTEINFO structure, and then either WaitForSingleObject or RegisterWaitForSingleObject on the process handle returned in the hProcess field of the SHELLEXECUTEINFO structure.

Comments