1 /*
2  * PROJECT:     ReactOS Automatic Testing Utility
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Class able to create a new process and closing its handles on destruction (exception-safe)
5  * COPYRIGHT:   Copyright 2009-2019 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 /**
11  * Constructs a CProcess object and uses the CreateProcessW function to start the process immediately.
12  *
13  * @param CommandLine
14  * A std::wstring containing the command line to run
15  *
16  * @param StartupInfo
17  * Pointer to a STARTUPINFOW structure containing process startup information
18  */
19 CProcess::CProcess(const wstring& CommandLine, LPSTARTUPINFOW StartupInfo)
20 {
21     auto_array_ptr<WCHAR> CommandLinePtr(new WCHAR[CommandLine.size() + 1]);
22 
23     wcscpy(CommandLinePtr, CommandLine.c_str());
24 
25     if(!CreateProcessW(NULL, CommandLinePtr, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo))
26         TESTEXCEPTION("CreateProcessW failed\n");
27 }
28 
29 /**
30  * Destructs a CProcess object, terminates the process if running, and closes all handles belonging to the process.
31  */
32 CProcess::~CProcess()
33 {
34     TerminateProcess(m_ProcessInfo.hProcess, 255);
35     CloseHandle(m_ProcessInfo.hThread);
36     CloseHandle(m_ProcessInfo.hProcess);
37 }
38