From 56c3bf848a09e4c34fbbb93ae68cea8a4892388c Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Sun, 11 Oct 2015 22:22:17 +0200 Subject: [PATCH] completly removed windows.h header, now i'll start with testing --- boost/detail/winapi/GetSystemDirectory.hpp | 57 +++++++++ boost/detail/winapi/process_api.hpp | 4 +- boost/detail/winapi/process_info.hpp | 2 +- boost/detail/winapi/shell_api.hpp | 135 +++++++++++++++++++++ boost/detail/winapi/show_windows.hpp | 24 ---- boost/process/config.hpp | 4 +- boost/process/windows/create_pipe.hpp | 1 - boost/process/windows/pipe.hpp | 5 +- boost/process/windows/search_path.hpp | 8 +- boost/process/windows/shell_path.hpp | 12 +- boost/process/windows/terminate.hpp | 6 +- 11 files changed, 215 insertions(+), 43 deletions(-) create mode 100644 boost/detail/winapi/GetSystemDirectory.hpp create mode 100644 boost/detail/winapi/shell_api.hpp diff --git a/boost/detail/winapi/GetSystemDirectory.hpp b/boost/detail/winapi/GetSystemDirectory.hpp new file mode 100644 index 00000000..d275d734 --- /dev/null +++ b/boost/detail/winapi/GetSystemDirectory.hpp @@ -0,0 +1,57 @@ +/* + * GetSystemDirectory.hpp + * + * Created on: 11.10.2015 + * Author: Klemens + */ + +#ifndef BOOST_DETAIL_WINAPI_GETSYSTEMDIRECTORY_HPP_ +#define BOOST_DETAIL_WINAPI_GETSYSTEMDIRECTORY_HPP_ + +#include + + +namespace boost +{ +namespace detail +{ +namespace winapi +{ +extern "C" { + +#if defined( BOOST_USE_WINDOWS_H ) + +using ::GetSystemDirectoryA; +using ::GetSystemDirectoryW; + +#else + +__declspec(dllimport) unsigned int WINAPI GetSystemDirectoryA (LPSTR_ lpBuffer, unsigned int uSize); +__declspec(dllimport) unsigned int WINAPI GetSystemDirectoryW (LPWSTR_ lpBuffer, unsigned int uSize); + + +#if defined(UNICODE) || defined(_UNICODE) +inline unsigned int GetSystemDirectory (LPWSTR_ lpBuffer, unsigned int uSize) +{ + return GetSystemDirectoryW(lpBuffer, uSize); +} + +#else +inline unsigned int GetSystemDirectory (LPSTR_ lpBuffer, unsigned int uSize) +{ + return GetSystemDirectoryA(lpBuffer, uSize); +} + +#endif +} + +} + +} +} + + + + + +#endif /* BOOST_DETAIL_WINAPI_GETSYSTEMDIRECTORY_HPP_ */ diff --git a/boost/detail/winapi/process_api.hpp b/boost/detail/winapi/process_api.hpp index d9985e8b..6fa0643a 100644 --- a/boost/detail/winapi/process_api.hpp +++ b/boost/detail/winapi/process_api.hpp @@ -34,7 +34,7 @@ using ::CreateProcessW; #else __declspec(dllimport) __declspec (noreturn) void WINAPI ExitProcess (unsigned int uExitCode); -__declspec(dllimport) int WINAPI TerminateProcess (HANDLE_ hProcess, unsigned int uExitCode); +__declspec(dllimport) int WINAPI TerminateProcess (HANDLE_ hProcess, unsigned int uExitCode); __declspec(dllimport) int WINAPI GetExitCodeProcess (HANDLE_ hProcess, DWORD_* lpExitCode); __declspec(dllimport) int WINAPI CreateProcessA (LPCSTR_ lpApplicationName, LPSTR_ lpCommandLine, LPSECURITY_ATTRIBUTES_ lpProcessAttributes, LPSECURITY_ATTRIBUTES_ lpThreadAttributes, int bInheritHandles, DWORD_ dwCreationFlags, LPVOID_ lpEnvironment, LPCSTR_ lpCurrentDirectory, STARTUPINFOA_* lpStartupInfo, PROCESS_INFORMATION_* lpProcessInformation); @@ -42,7 +42,6 @@ __declspec(dllimport) int WINAPI CreateProcessW (LPCWSTR_ lpApplicationName, LPW } -#endif #if defined(UNICODE) || defined(_UNICODE) inline int CreateProcess (LPCWSTR_ lpApplicationName, LPWSTR_ lpCommandLine, LPSECURITY_ATTRIBUTES_ lpProcessAttributes, LPSECURITY_ATTRIBUTES_ lpThreadAttributes, int bInheritHandles, DWORD_ dwCreationFlags, LPVOID_ lpEnvironment, LPCWSTR_ lpCurrentDirectory, STARTUPINFOW_* lpStartupInfo, PROCESS_INFORMATION_* lpProcessInformation) @@ -55,6 +54,7 @@ inline int CreateProcess (LPCSTR_ lpApplicationName, LPSTR_ lpCommandLine, LPSE return CreateProcessA (lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); } #endif +#endif } diff --git a/boost/detail/winapi/process_info.hpp b/boost/detail/winapi/process_info.hpp index 76a46c27..1762d12b 100644 --- a/boost/detail/winapi/process_info.hpp +++ b/boost/detail/winapi/process_info.hpp @@ -81,7 +81,6 @@ struct STARTUPINFOW_ { HANDLE_ hStdError; } ; -#endif #if defined(UNICODE) || defined(_UNICODE) typedef STARTUPINFOW_ STARTUPINFO_; @@ -102,6 +101,7 @@ struct STARTUPINFOEX_ { PROC_THREAD_ATTRIBUTE_LIST_* lpAttributeList; }; +#endif #endif } }}} diff --git a/boost/detail/winapi/shell_api.hpp b/boost/detail/winapi/shell_api.hpp new file mode 100644 index 00000000..ac200130 --- /dev/null +++ b/boost/detail/winapi/shell_api.hpp @@ -0,0 +1,135 @@ +/* + * shell_api.hpp + * + * Created on: 11.10.2015 + * Author: Klemens + */ + +#ifndef BOOST_DETAIL_WINAPI_SHELL_API_HPP_ +#define BOOST_DETAIL_WINAPI_SHELL_API_HPP_ + + + + +#include +#include + + +namespace boost +{ +namespace detail +{ +namespace winapi +{ +extern "C" { + +#if defined( BOOST_USE_WINDOWS_H ) + +const DWORD_ shgfi_icon = SHGFI_ICON ; +const DWORD_ shgfi_displayname = SHGFI_DISPLAYNAME ; +const DWORD_ shgfi_typename = SHGFI_TYPENAME ; +const DWORD_ shgfi_attributes = SHGFI_ATTRIBUTES ; +const DWORD_ shgfi_iconlocation = SHGFI_ICONLOCATION ; +const DWORD_ shgfi_exetype = SHGFI_EXETYPE ; +const DWORD_ shgfi_sysiconindex = SHGFI_SYSICONINDEX ; +const DWORD_ shgfi_linkoverlay = SHGFI_LINKOVERLAY ; +const DWORD_ shgfi_selected = SHGFI_SELECTED ; +const DWORD_ shgfi_attr_specified = SHGFI_ATTR_SPECIFIED ; +const DWORD_ shgfi_largeicon = SHGFI_LARGEICON ; +const DWORD_ shgfi_smallicon = SHGFI_SMALLICON ; +const DWORD_ shgfi_openicon = SHGFI_OPENICON ; +const DWORD_ shgfi_shelliconsize = SHGFI_SHELLICONSIZE ; +const DWORD_ shgfi_pidl = SHGFI_PIDL ; +const DWORD_ shgfi_usefileattributes = SHGFI_USEFILEATTRIBUTES; +const DWORD_ shgfi_addoverlays = SHGFI_ADDOVERLAYS ; +const DWORD_ shgfi_overlayindex = SHGFI_OVERLAYINDEX ; +const DWORD_ max_path = MAX_PATH; + + +using ::SHGetFileInfoA; +using ::SHGetFileInfoW; + +typedef ::SHFILEINFOA SHFILEINFOA_; +typedef ::SHFILEINFOW SHFILEINFOW_; + +#else + +struct ICON_ {}; +typedef ICON_ *HICON_; + +const DWORD_ max_path = 260; + +struct SHFILEINFOA_ { + HICON_ hIcon; + int iIcon; + DWORD_ dwAttributes; + CHAR_ szDisplayName[260]; + CHAR_ szTypeName[80]; +} ; + +struct SHFILEINFOW_ { + HICON_ hIcon; + int iIcon; + DWORD_ dwAttributes; + WCHAR_ szDisplayName[260]; + WCHAR_ szTypeName[80]; +}; + + +const DWORD_ shgfi_icon = 0x000000100; +const DWORD_ shgfi_displayname = 0x000000200; +const DWORD_ shgfi_typename = 0x000000400; +const DWORD_ shgfi_attributes = 0x000000800; +const DWORD_ shgfi_iconlocation = 0x000001000; +const DWORD_ shgfi_exetype = 0x000002000; +const DWORD_ shgfi_sysiconindex = 0x000004000; +const DWORD_ shgfi_linkoverlay = 0x000008000; +const DWORD_ shgfi_selected = 0x000010000; +const DWORD_ shgfi_attr_specified = 0x000020000; +const DWORD_ shgfi_largeicon = 0x000000000; +const DWORD_ shgfi_smallicon = 0x000000001; +const DWORD_ shgfi_openicon = 0x000000002; +const DWORD_ shgfi_shelliconsize = 0x000000004; +const DWORD_ shgfi_pidl = 0x000000008; +const DWORD_ shgfi_usefileattributes = 0x000000010; +const DWORD_ shgfi_addoverlays = 0x000000020; +const DWORD_ shgfi_overlayindex = 0x000000040; + +__declspec(dllimport) DWORD_* WINAPI SHGetFileInfoA (LPCSTR_ pszPath, DWORD_ dwFileAttributes, SHFILEINFOA_ *psfinsigned, unsigned int cbFileInfons, unsigned int uFlags); +__declspec(dllimport) DWORD_* WINAPI SHGetFileInfoW (LPCWSTR_ pszPath, DWORD_ dwFileAttributes, SHFILEINFOW_ *psfinsigned, unsigned int cbFileInfons, unsigned int uFlags); + + +} + + +#endif + + +#if defined(UNICODE) || definde(_UNICODE) +typedef SHFILEINFOW_ SHFILEINFO_; +inline DWORD_* SHGetFileInfo (LPCWSTR_ pszPath, DWORD_ dwFileAttributes, SHFILEINFOW_ *psfinsigned, unsigned int cbFileInfons, unsigned int uFlags) +{ + return SHGetFileInfoW(pszPath, dwFileAttributes, psfinsigned, cbFileInfons, uFlags); +} + + +#else +typedef SHFILEINFOA_ SHFILEINFO_; +inline DWORD_* SHGetFileInfo (LPCSTR_ pszPath, DWORD_ dwFileAttributes, SHFILEINFOA_ *psfinsigned, unsigned int cbFileInfons, unsigned int uFlags) +{ + return SHGetFileInfoA (pszPath, dwFileAttributes, psfinsigned, cbFileInfons, uFlags); +} + + + + +#endif + +} + +} +} + + + +#endif /* BOOST_DETAIL_WINAPI_SHELL_API_HPP_ */ diff --git a/boost/detail/winapi/show_windows.hpp b/boost/detail/winapi/show_windows.hpp index 559253ba..d941f34c 100644 --- a/boost/detail/winapi/show_windows.hpp +++ b/boost/detail/winapi/show_windows.hpp @@ -89,28 +89,4 @@ const DWORD_ sw_otherunzoom = 4 ; } } -//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_ */ diff --git a/boost/process/config.hpp b/boost/process/config.hpp index 7aae4d3c..b03b17e0 100644 --- a/boost/process/config.hpp +++ b/boost/process/config.hpp @@ -26,8 +26,8 @@ # define BOOST_PROCESS_LAST_ERROR errno # define BOOST_PROCESS_PLATFORM posix #elif defined(BOOST_WINDOWS_API) -# include -# define BOOST_PROCESS_LAST_ERROR GetLastError() +# include +# define BOOST_PROCESS_LAST_ERROR ::boost::detail::winapi::GetLastError() # define BOOST_PROCESS_PLATFORM windows #endif diff --git a/boost/process/windows/create_pipe.hpp b/boost/process/windows/create_pipe.hpp index 8e02adc0..4035320a 100644 --- a/boost/process/windows/create_pipe.hpp +++ b/boost/process/windows/create_pipe.hpp @@ -13,7 +13,6 @@ #include #include #include -#include namespace boost { namespace process { namespace windows { diff --git a/boost/process/windows/pipe.hpp b/boost/process/windows/pipe.hpp index 1dd85667..e05aab18 100644 --- a/boost/process/windows/pipe.hpp +++ b/boost/process/windows/pipe.hpp @@ -19,10 +19,11 @@ struct pipe boost::detail::winapi::HANDLE_ source; boost::detail::winapi::HANDLE_ sink; - pipe(HANDLE source, HANDLE sink) : source(source), sink(sink) {} + pipe(boost::detail::winapi::HANDLE_ source, boost::detail::winapi::HANDLE_ sink) : source(source), sink(sink) {} }; -inline pipe make_pipe(HANDLE source, HANDLE sink) +inline pipe make_pipe(boost::detail::winapi::HANDLE_ source, + boost::detail::winapi::HANDLE_ sink) { return pipe(source, sink); } diff --git a/boost/process/windows/search_path.hpp b/boost/process/windows/search_path.hpp index 62bb5f27..d38b0487 100644 --- a/boost/process/windows/search_path.hpp +++ b/boost/process/windows/search_path.hpp @@ -18,7 +18,9 @@ #include #include #include -#include +#include + + namespace boost { namespace process { namespace windows { @@ -52,7 +54,7 @@ inline std::wstring search_path(const std::wstring &filename, boost::system::error_code ec; bool file = boost::filesystem::is_regular_file(p2, ec); if (!ec && file && - SHGetFileInfoW(p2.c_str(), 0, 0, 0, SHGFI_EXETYPE)) + ::boost::detail::winapi::SHGetFileInfoW(p2.c_str(), 0, 0, 0, ::boost::detail::winapi::shgfi_exetype)) { return p2.wstring(); } @@ -89,7 +91,7 @@ inline std::string search_path(const std::string &filename, boost::system::error_code ec; bool file = boost::filesystem::is_regular_file(p2, ec); if (!ec && file && - SHGetFileInfoA(p2.string().c_str(), 0, 0, 0, SHGFI_EXETYPE)) + ::boost::detail::winapi::SHGetFileInfoA(p2.string().c_str(), 0, 0, 0, ::boost::detail::winapi::shgfi_exetype)) { return p2.string(); } diff --git a/boost/process/windows/shell_path.hpp b/boost/process/windows/shell_path.hpp index ace15b96..78ccba8b 100644 --- a/boost/process/windows/shell_path.hpp +++ b/boost/process/windows/shell_path.hpp @@ -13,14 +13,16 @@ #include #include #include -#include +#include +#include namespace boost { namespace process { namespace windows { inline boost::filesystem::path shell_path() { - TCHAR sysdir[MAX_PATH]; - UINT size = ::GetSystemDirectory(sysdir, sizeof(sysdir)); + //260 is MAX_PATH but should be sufficient anyway. + char sysdir[260]; + unsigned int size = ::boost::detail::winapi::GetSystemDirectory(sysdir, sizeof(sysdir)); if (!size) BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("GetSystemDirectory() failed"); boost::filesystem::path p = sysdir; @@ -29,8 +31,8 @@ inline boost::filesystem::path shell_path() inline boost::filesystem::path shell_path(boost::system::error_code &ec) { - TCHAR sysdir[MAX_PATH]; - UINT size = ::GetSystemDirectory(sysdir, sizeof(sysdir)); + char sysdir[260]; + unsigned int size = ::boost::detail::winapi::GetSystemDirectory(sysdir, sizeof(sysdir)); boost::filesystem::path p; if (!size) { diff --git a/boost/process/windows/terminate.hpp b/boost/process/windows/terminate.hpp index 43afe250..cc4a4621 100644 --- a/boost/process/windows/terminate.hpp +++ b/boost/process/windows/terminate.hpp @@ -13,21 +13,21 @@ #include #include #include -#include +#include namespace boost { namespace process { namespace windows { template void terminate(const Process &p) { - if (!::TerminateProcess(p.process_handle(), EXIT_FAILURE)) + if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE)) BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("TerminateProcess() failed"); } template void terminate(const Process &p, boost::system::error_code &ec) { - if (!::TerminateProcess(p.process_handle(), EXIT_FAILURE)) + if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE)) BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec); else ec.clear();