2
0
mirror of https://github.com/boostorg/process.git synced 2026-01-19 04:22:15 +00:00

started on removing the #include <Windows.h>

This commit is contained in:
klemens-morgenstern
2015-10-11 16:55:36 +02:00
parent 9a19312ddf
commit 6942020ccc
11 changed files with 322 additions and 23 deletions

View File

@@ -0,0 +1,54 @@
/*
* handleapi.hpp
*
* Created on: 11.10.2015
* Author: Klemens
*/
#ifndef BOOST_DETAIL_HANDLEAPI_HPP_
#define BOOST_DETAIL_HANDLEAPI_HPP_
#include <boost/detail/winapi/basic_types.hpp>
#include <boost/detail/winapi/config.hpp>
#include <boost/detail/winapi/handles.hpp>
//HANDLE_FLAG_INHERIT HANDLE_FLAG_INHERIT
namespace boost
{
namespace detail
{
namespace winapi
{
extern "C" {
#if defined( BOOST_USE_WINDOWS_H )
using ::GetHandleInformation;
using ::SetHandleInformation;
const DWORD_ handle_flag_inherit = HANDLE_FLAG_INHERIT;
const DWORD_ handle_flag_protect_from_close = HANDLE_FLAG_PROTECT_FROM_CLOSE;
#else
const DWORD_ handle_flag_inherit = 0x1;
const DWORD_ handle_flag_protect_from_close = 0x2;
__declspec(dllimport) int WINAPI GetHandleInformation (HANDLE_ hObject, DWORD_* lpdwFlags);
__declspec(dllimport) int WINAPI SetHandleInformation (HANDLE_ hObject, DWORD_ dwMask, DWORD_ dwFlags);
}
#endif
}
}
}
#endif /* BOOST_DETAIL_HANDLEAPI_HPP_ */

View File

@@ -0,0 +1,48 @@
/*
* HANDLE_api.hpp
*
* Created on: 11.10.2015
* Author: Klemens
*/
#ifndef BOOST_DETAIL_HANDLE_API_HPP_
#define BOOST_DETAIL_HANDLE_API_HPP_
#include <boost/detail/winapi/basic_types.hpp>
#include <boost/detail/winapi/config.hpp>
//HANDLE_FLAG_INHERIT HANDLE_FLAG_INHERIT
namespace boost
{
namespace detail
{
namespace winapi
{
extern "C" {
#if defined( BOOST_USE_WINDOWS_H )
using ::GetExitCodeProcess;
using ::ExitProcess;
using ::TerminateProcess;
#else
__declspec(dllimport) __declspec (noreturn) void WINAPI ExitProcess (UINT_ uExitCode);
__declspec(dllimport) int WINAPI TerminateProcess (HANDLE_ hProcess, UINT_ uExitCode);
__declspec(dllimport) int WINAPI GetExitCodeProcess (HANDLE_ hProcess, LPDWORD_ lpExitCode);
}
#endif
}
}
}
#endif /* BOOST_DETAIL_HANDLE_API_HPP_ */

View File

@@ -0,0 +1,115 @@
/*
* show_windows.hpp
*
* Created on: 11.10.2015
* Author: Klemens
*/
#ifndef BOOST_DETAIL_WINAPI_SHOW_WINDOWS_HPP_
#define BOOST_DETAIL_WINAPI_SHOW_WINDOWS_HPP_
#include <boost/detail/winapi/basic_types.hpp>
namespace boost
{
namespace detail
{
namespace winapi
{
extern "C" {
#if defined( BOOST_USE_WINDOWS_H )
const DWOD_ sw_hide = SW_HIDE ;
const DWOD_ sw_shownormal = SW_SHOWNORMAL ;
const DWOD_ sw_normal = SW_NORMAL ;
const DWOD_ sw_showminimized = SW_SHOWMINIMIZED ;
const DWOD_ sw_showmaximized = SW_SHOWMAXIMIZED ;
const DWOD_ sw_maximize = SW_MAXIMIZE ;
const DWOD_ sw_shownoactivate = SW_SHOWNOACTIVATE ;
const DWOD_ sw_show = SW_SHOW ;
const DWOD_ sw_minimize = SW_MINIMIZE ;
const DWOD_ sw_showminnoactive = SW_SHOWMINNOACTIVE ;
const DWOD_ sw_showna = SW_SHOWNA ;
const DWOD_ sw_restore = SW_RESTORE ;
const DWOD_ sw_showdefault = SW_SHOWDEFAULT ;
const DWOD_ sw_forceminimize = SW_FORCEMINIMIZE ;
const DWOD_ sw_max = SW_MAX ;
const DWOD_ hide_window = HIDE_WINDOW ;
const DWOD_ show_openwindow = SHOW_OPENWINDOW ;
const DWOD_ show_iconwindow = SHOW_ICONWINDOW ;
const DWOD_ show_fullscreen = SHOW_FULLSCREEN ;
const DWOD_ show_opennoactivate = SHOW_OPENNOACTIVATE ;
const DWOD_ sw_parentclosing = SW_PARENTCLOSING ;
const DWOD_ sw_otherzoom = SW_OTHERZOOM ;
const DWOD_ sw_parentopening = SW_PARENTOPENING ;
const DWOD_ sw_otherunzoom = SW_OTHERUNZOOM ;
#else
const DWORD_ sw_hide = 0 ;
const DWORD_ sw_shownormal = 1 ;
const DWORD_ sw_normal = 1 ;
const DWORD_ sw_showminimized = 2 ;
const DWORD_ sw_showmaximized = 3 ;
const DWORD_ sw_maximize = 3 ;
const DWORD_ sw_shownoactivate = 4 ;
const DWORD_ sw_show = 5 ;
const DWORD_ sw_minimize = 6 ;
const DWORD_ sw_showminnoactive = 7 ;
const DWORD_ sw_showna = 8 ;
const DWORD_ sw_restore = 9 ;
const DWORD_ sw_showdefault = 10;
const DWORD_ sw_forceminimize = 11;
const DWORD_ sw_max = 11;
const DWORD_ hide_window = 0 ;
const DWORD_ show_openwindow = 1 ;
const DWORD_ show_iconwindow = 2 ;
const DWORD_ show_fullscreen = 3 ;
const DWORD_ show_opennoactivate = 4 ;
const DWORD_ sw_parentclosing = 1 ;
const DWORD_ sw_otherzoom = 2 ;
const DWORD_ sw_parentopening = 3 ;
const DWORD_ sw_otherunzoom = 4 ;
}
#endif
}
}
}
//STARTF_USESTDHANDLES
#ifndef NOSHOWWINDOW
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11
#endif /* BOOST_DETAIL_WINAPI_SHOW_WINDOWS_HPP_ */

View File

@@ -0,0 +1,67 @@
/*
* startf.hpp
*
* Created on: 11.10.2015
* Author: Klemens
*/
#ifndef BOOST_DETAIL_WINAPI_STARTF_HPP_
#define BOOST_DETAIL_WINAPI_STARTF_HPP_
#include <boost/detail/winapi/basic_types.hpp>
namespace boost
{
namespace detail
{
namespace winapi
{
extern "C" {
#if defined( BOOST_USE_WINDOWS_H )
const DWORD_ startf_useshowwindow = STARTF_USESHOWWINDOW ;
const DWORD_ startf_usesize = STARTF_USESIZE ;
const DWORD_ startf_useposition = STARTF_USEPOSITION ;
const DWORD_ startf_usecountchars = STARTF_USECOUNTCHARS ;
const DWORD_ startf_usefillattribute = STARTF_USEFILLATTRIBUTE;
const DWORD_ startf_runfullscreen = STARTF_RUNFULLSCREEN ;
const DWORD_ startf_forceonfeedback = STARTF_FORCEONFEEDBACK ;
const DWORD_ startf_forceofffeedback = STARTF_FORCEOFFFEEDBACK;
const DWORD_ startf_usestdhandles = STARTF_USESTDHANDLES ;
const DWORD_ startf_usehotkey = STARTF_USEHOTKEY ;
const DWORD_ startf_titleislinkname = STARTF_TITLEISLINKNAME ;
const DWORD_ startf_titleisappid = STARTF_TITLEISAPPID ;
const DWORD_ startf_preventpinning = STARTF_PREVENTPINNING ;
#else
const DWORD_ startf_useshowwindow = 0x00000001;
const DWORD_ startf_usesize = 0x00000002;
const DWORD_ startf_useposition = 0x00000004;
const DWORD_ startf_usecountchars = 0x00000008;
const DWORD_ startf_usefillattribute = 0x00000010;
const DWORD_ startf_runfullscreen = 0x00000020;
const DWORD_ startf_forceonfeedback = 0x00000040;
const DWORD_ startf_forceofffeedback = 0x00000080;
const DWORD_ startf_usestdhandles = 0x00000100;
const DWORD_ startf_usehotkey = 0x00000200;
const DWORD_ startf_titleislinkname = 0x00000800;
const DWORD_ startf_titleisappid = 0x00001000;
const DWORD_ startf_preventpinning = 0x00002000;
}
#endif
}
}
}
//STARTF_USESTDHANDLES
#endif /* BOOST_DETAIL_WINAPI_STARTF_HPP_ */

View File

@@ -12,7 +12,9 @@
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <Windows.h>
#include <boost/detail/winapi/handle_info.hpp>
#include <boost/detail/winapi/startf.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -24,9 +26,12 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
::SetHandleInformation(sink_.handle(), HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
::boost::detail::winapi::SetHandleInformation(
sink_.handle(),
::boost::detail::winapi::handle_flag_inherit,
::boost::detail::winapi::handle_flag_inherit);
e.startup_info.hStdError = sink_.handle();
e.startup_info.dwFlags |= STARTF_USESTDHANDLES;
e.startup_info.dwFlags |= ::boost::detail::winapi::startf_usestdhandles;
e.inherit_handles = true;
}

View File

@@ -12,7 +12,8 @@
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <Windows.h>
#include <boost/detail/winapi/handle_info.hpp>
#include <boost/detail/winapi/startf.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -24,9 +25,11 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
::SetHandleInformation(source_.handle(), HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
::boost::detail::winapi::SetHandleInformation(source_.handle(),
::boost::detail::winapi::handle_flag_inherit,
::boost::detail::winapi::handle_flag_inherit);
e.startup_info.hStdInput = source_.handle();
e.startup_info.dwFlags |= STARTF_USESTDHANDLES;
e.startup_info.dwFlags |= ::boost::detail::winapi::startf_usestdhandles;
e.inherit_handles = true;
}

View File

@@ -12,7 +12,8 @@
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <Windows.h>
#include <boost/detail/winapi/handle_info.hpp>
#include <boost/detail/winapi/startf.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -24,9 +25,12 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
::SetHandleInformation(sink_.handle(), HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
::boost::detail::winapi::SetHandleInformation(
sink_.handle(),
::boost::detail::winapi::handle_flag_inherit,
::boost::detail::winapi::handle_flag_inherit);
e.startup_info.hStdOutput = sink_.handle();
e.startup_info.dwFlags |= STARTF_USESTDHANDLES;
e.startup_info.dwFlags |= ::boost::detail::winapi::startf_usestdhandles;
e.inherit_handles = true;
}

View File

@@ -11,7 +11,8 @@
#define BOOST_PROCESS_WINDOWS_INITIALIZERS_CLOSE_STDERR_HPP
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <Windows.h>
#include <boost/detail/winapi/startf.hpp>
#include <boost/detail/winapi/handles.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -21,8 +22,8 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
e.startup_info.hStdError = INVALID_HANDLE_VALUE;
e.startup_info.dwFlags |= STARTF_USESTDHANDLES;
e.startup_info.hStdError = ::boost::detail::winapi::invalid_handle_value;
e.startup_info.dwFlags |= ::boost::detail::winapi::startf_usestdhandles;
}
};

View File

@@ -11,7 +11,8 @@
#define BOOST_PROCESS_WINDOWS_INITIALIZERS_CLOSE_STDIN_HPP
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <Windows.h>
#include <boost/detail/winapi/startf.hpp>
#include <boost/detail/winapi/handles.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -21,8 +22,8 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
e.startup_info.hStdInput = INVALID_HANDLE_VALUE;
e.startup_info.dwFlags |= STARTF_USESTDHANDLES;
e.startup_info.hStdInput = boost::detail::winapi::invalid_handle_value;
e.startup_info.dwFlags |= boost::detail::winapi::startf_usestdhandles;
}
};

View File

@@ -11,7 +11,7 @@
#define BOOST_PROCESS_WINDOWS_INITIALIZERS_HIDE_CONSOLE_HPP
#include <boost/process/windows/initializers/initializer_base.hpp>
#include <Windows.h>
#include <boost/detail/winapi/startf.hpp>
namespace boost { namespace process { namespace windows { namespace initializers {
@@ -21,8 +21,8 @@ public:
template <class WindowsExecutor>
void on_CreateProcess_setup(WindowsExecutor &e) const
{
e.startup_info.dwFlags |= STARTF_USESHOWWINDOW;
e.startup_info.wShowWindow |= SW_HIDE;
e.startup_info.dwFlags |= ::boost::detail::winapi::startf_useshowwindow;
e.startup_info.wShowWindow |= ::boost::detail::winapi::sw_hide;
}
};

View File

@@ -12,18 +12,19 @@
#include <boost/process/config.hpp>
#include <boost/system/error_code.hpp>
#include <Windows.h>
#include <boost/detail/winapi/synchronization.hpp>
#include <boost/detail/winapi/process_api.hpp>
namespace boost { namespace process { namespace windows {
template <class Process>
inline DWORD wait_for_exit(const Process &p)
{
if (::WaitForSingleObject(p.process_handle(), INFINITE) == WAIT_FAILED)
if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(), ::boost::detail::winapi::infinite) == ::boost::detail::winapi::wait_failed)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("WaitForSingleObject() failed");
DWORD exit_code;
if (!::GetExitCodeProcess(p.process_handle(), &exit_code))
if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &exit_code))
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("GetExitCodeProcess() failed");
return exit_code;
@@ -34,9 +35,9 @@ inline DWORD wait_for_exit(const Process &p, boost::system::error_code &ec)
{
DWORD exit_code = 1;
if (::WaitForSingleObject(p.process_handle(), INFINITE) == WAIT_FAILED)
if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(), ::boost::detail::winapi::infinite) == ::boost::detail::winapi::wait_failed)
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
else if (!::GetExitCodeProcess(p.process_handle(), &exit_code))
else if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &exit_code))
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
else
ec.clear();