I have this class which runs another program, and when the instance of that class gets deleted, I let it kill the program that it opened. Now it may have been the case where the user has closes this new program himself, in this case, the object should detect that and destroy itself. There is a method in this class which allows me to check every ~50ms. The question is, how do I check if the program I opened is still running or not?
I tried to ask for the threadid and check if it returned a 0, but it keeps returning the "correct" threadid even when the program has been closed. Tried the same with processid.

Code:
void AppMenu::Run(const tstring& exe, const tstring& param)
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &pi, sizeof(pi) );
	tstring runcmd = exe;
	if (!param.empty())
		runcmd += _T(" \"") + param + _T("\"");
	tstring startpath = runcmd.substr(0,runcmd.find_last_of(_T("\\/")) + 1);
	TCHAR *tmp;
	size_t bufsize = runcmd.length() + 1; // +1 to include the \0
	tmp = new TCHAR[bufsize];
	_tcscpy_s(tmp,bufsize,runcmd.c_str());
	if (!CreateProcess( NULL,   // No module name (use command line)
		tmp ,       // Command line
		NULL,           // Process handle not inheritable
		NULL,           // Thread handle not inheritable
		FALSE,          // Set handle inheritance to FALSE
		0,              // No creation flags
		NULL,           // Use parent's environment block
		startpath.c_str(), // Use given starting directory 
		&si,            // Pointer to STARTUPINFO structure
		&pi )          // Pointer to PROCESS_INFORMATION structure
		)
	{
		delete[] tmp;
		return;
	}
	delete[] tmp;
	m_ThreadID = pi.dwThreadId;
	m_ProcessID = pi.dwProcessId;
	m_hThread = pi.hThread;
	m_hProcess = pi.hProcess;
}
As you can see I can use the handles and id's for checking if it exists, but now I need to know what function to use.