// Runs an application and waits for it to return.
//
// Dependencies: CString
// Status: unchecked
//
// Web: http://unclassified.software/source/runapplication
//
int RunApplication(CString strPath, CString strArgs)
{
	BOOL				rc;
	STARTUPINFO			si;
	PROCESS_INFORMATION pi;
	CString				strCmdLine;

	strCmdLine.Format("%s %s", strPath, strArgs);
	// TODO: why don't we use CreateProcess' 1st parameter?
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	ZeroMemory(&pi, sizeof(pi));
	rc = CreateProcess(NULL,
				strCmdLine.GetBuffer(strCmdLine.GetLength() + 1),
				NULL,
				NULL,
				FALSE,
				0,
				NULL,
				NULL,
				&si,
				&pi);
	if (rc)
	{
		WaitForSingleObject(pi.hProcess, INFINITE);	// Wait until child process exits.
		CloseHandle(pi.hProcess);					// Close process and thread handles.
		CloseHandle(pi.hThread);
	}
	return rc;
}
