You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/process/functions.h
  3. *
  4. * Purpose: Process functions.
  5. *
  6. * Created: 12th March 2006
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2006-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/process/functions.h
  40. *
  41. * \brief [C, C++] Process control functions
  42. * (\ref group__library__system "System" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_PROCESS_H_FUNCTIONS
  45. #define WINSTL_INCL_WINSTL_PROCESS_H_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_PROCESS_H_FUNCTIONS_MAJOR 1
  48. # define WINSTL_VER_WINSTL_PROCESS_H_FUNCTIONS_MINOR 0
  49. # define WINSTL_VER_WINSTL_PROCESS_H_FUNCTIONS_REVISION 5
  50. # define WINSTL_VER_WINSTL_PROCESS_H_FUNCTIONS_EDIT 18
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  56. # include <winstl/winstl.h>
  57. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  58. #ifndef STLSOFT_INCL_H_STRING
  59. # define STLSOFT_INCL_H_STRING
  60. # include <string.h>
  61. #endif /* !STLSOFT_INCL_H_STRING */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Namespace
  64. */
  65. #if !defined(_WINSTL_NO_NAMESPACE) && \
  66. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  67. # if defined(_STLSOFT_NO_NAMESPACE)
  68. /* There is no stlsoft namespace, so must define ::winstl */
  69. namespace winstl
  70. {
  71. # else
  72. /* Define stlsoft::winstl_project */
  73. namespace stlsoft
  74. {
  75. namespace winstl_project
  76. {
  77. # endif /* _STLSOFT_NO_NAMESPACE */
  78. #endif /* !_WINSTL_NO_NAMESPACE */
  79. /* /////////////////////////////////////////////////////////////////////////
  80. * C functions
  81. */
  82. /**
  83. *
  84. * \ingroup group__library__system
  85. */
  86. STLSOFT_INLINE BOOL winstl__CreateProcessFEA(ws_char_a_t const* cmdLine, DWORD flags, void const* envBlock)
  87. {
  88. STARTUPINFO si;
  89. PROCESS_INFORMATION pi;
  90. BOOL b;
  91. STLSOFT_NS_GLOBAL(memset)(&si, 0, sizeof(si));
  92. b = STLSOFT_NS_GLOBAL(CreateProcessA)(NULL, stlsoft_const_cast(ws_char_a_t*, cmdLine), NULL, NULL, FALSE, flags, stlsoft_const_cast(void*, envBlock), NULL, &si, &pi);
  93. if(b)
  94. {
  95. STLSOFT_NS_GLOBAL(CloseHandle)(pi.hProcess);
  96. STLSOFT_NS_GLOBAL(CloseHandle)(pi.hThread);
  97. }
  98. return b;
  99. }
  100. /**
  101. *
  102. * \ingroup group__library__system
  103. */
  104. STLSOFT_INLINE BOOL winstl__CreateProcessEA(ws_char_a_t const* cmdLine, void const* envBlock)
  105. {
  106. return winstl__CreateProcessFEA(cmdLine, 0, envBlock);
  107. }
  108. /**
  109. *
  110. * \ingroup group__library__system
  111. */
  112. STLSOFT_INLINE BOOL winstl__CreateProcess0A(ws_char_a_t const* cmdLine)
  113. {
  114. return winstl__CreateProcessEA(cmdLine, NULL);
  115. }
  116. /* /////////////////////////////////////////////////////////////////////////
  117. * Namespace
  118. */
  119. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  120. namespace winstl
  121. {
  122. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  123. /* /////////////////////////////////////////////////////////////////////////
  124. * C++ functions
  125. */
  126. #ifdef __cplusplus
  127. /**
  128. *
  129. * \ingroup group__library__system
  130. */
  131. inline BOOL CreateProcess(ws_char_a_t const* cmdLine, DWORD flags, void const* envBlock)
  132. {
  133. return winstl__CreateProcessFEA(cmdLine, flags, envBlock);
  134. }
  135. /**
  136. *
  137. * \ingroup group__library__system
  138. */
  139. inline BOOL CreateProcess(ws_char_a_t const* cmdLine, void const* envBlock)
  140. {
  141. return winstl__CreateProcessEA(cmdLine, envBlock);
  142. }
  143. /**
  144. *
  145. * \ingroup group__library__system
  146. */
  147. inline BOOL CreateProcess(ws_char_a_t const* cmdLine)
  148. {
  149. return winstl__CreateProcess0A(cmdLine);
  150. }
  151. #endif /* __cplusplus */
  152. /* ////////////////////////////////////////////////////////////////////// */
  153. #ifndef _WINSTL_NO_NAMESPACE
  154. # if defined(_STLSOFT_NO_NAMESPACE) || \
  155. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  156. } /* namespace winstl */
  157. # else
  158. } /* namespace winstl_project */
  159. } /* namespace stlsoft */
  160. # endif /* _STLSOFT_NO_NAMESPACE */
  161. #endif /* !_WINSTL_NO_NAMESPACE */
  162. /* ////////////////////////////////////////////////////////////////////// */
  163. #endif /* WINSTL_INCL_WINSTL_PROCESS_H_FUNCTIONS */
  164. /* ///////////////////////////// end of file //////////////////////////// */