Merge from amd64-branch:
[reactos.git] / rostests / rosautotest / CProcess.cpp
1 /*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Class able to create a new process and closing its handles on destruction (exception-safe)
5 * COPYRIGHT: Copyright 2009 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 FATAL("CreateProcessW failed\n");
27 }
28
29 /**
30 * Destructs a CProcess object and closes all handles belonging to the process.
31 */
32 CProcess::~CProcess()
33 {
34 CloseHandle(m_ProcessInfo.hThread);
35 CloseHandle(m_ProcessInfo.hProcess);
36 }