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.

144 lines
5.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/toolhelp/thread_sequence.hpp
  3. *
  4. * Purpose: TOOLHELP thread sequence class.
  5. *
  6. * Created: 21st May 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Thanks: To Pablo for contributing this great library.
  10. *
  11. * Home: http://stlsoft.org/
  12. *
  13. * Copyright (c) 2005-2009, Pablo Aguilar
  14. * Copyright (c) 2006-2007, Matthew Wilson
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above copyright notice, this
  21. * list of conditions and the following disclaimer.
  22. * - Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * - Neither the name(s) of Matthew Wilson and Synesis Software, nor Pablo
  26. * Aguilar, nor the names of any contributors may be used to endorse or
  27. * promote products derived from this software without specific prior written
  28. * permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  38. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGE.
  41. *
  42. * ////////////////////////////////////////////////////////////////////// */
  43. /** \file winstl/toolhelp/thread_sequence.hpp
  44. *
  45. * \brief [C++ only] Definition of the
  46. * \link winstl::thread_sequence thread_sequence\endlink class
  47. * (\ref group__library__windows_toolhelp "Windows ToolHelp" Library).
  48. */
  49. #ifndef WINSTL_INCL_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE
  50. #define WINSTL_INCL_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE
  51. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  52. # define WINSTL_VER_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE_MAJOR 1
  53. # define WINSTL_VER_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE_MINOR 1
  54. # define WINSTL_VER_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE_REVISION 1
  55. # define WINSTL_VER_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE_EDIT 9
  56. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  57. /* /////////////////////////////////////////////////////////////////////////
  58. * Includes
  59. */
  60. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  61. # include <winstl/winstl.h>
  62. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  63. #ifdef STLSOFT_CF_PRAGMA_ONCE_SUPPORT
  64. # pragma once
  65. #endif /* STLSOFT_CF_PRAGMA_ONCE_SUPPORT */
  66. #ifndef WINSTL_INCL_WINSTL_TOOLHELP_HPP_SEQUENCE_BASE
  67. # include <winstl/toolhelp/sequence_base.hpp>
  68. #endif /* !WINSTL_INCL_WINSTL_TOOLHELP_HPP_SEQUENCE_BASE */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Namespace
  71. */
  72. #ifndef _WINSTL_NO_NAMESPACE
  73. # if defined(_STLSOFT_NO_NAMESPACE) || \
  74. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  75. /* There is no stlsoft namespace, so must define ::winstl */
  76. namespace winstl
  77. {
  78. # else
  79. /* Define stlsoft::winstl_project */
  80. namespace stlsoft
  81. {
  82. namespace winstl_project
  83. {
  84. # endif /* _STLSOFT_NO_NAMESPACE */
  85. #endif /* !_WINSTL_NO_NAMESPACE */
  86. /* /////////////////////////////////////////////////////////////////////////
  87. * Classes
  88. */
  89. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  90. #define WINSTL_TH_API_SEQUENCE_VALUE_TRAITS_VALUE THREADENTRY32
  91. #define WINSTL_TH_API_SEQUENCE_VALUE_TRAITS_FIRST Thread32First
  92. #define WINSTL_TH_API_SEQUENCE_VALUE_TRAITS_NEXT Thread32Next
  93. #define WINSTL_TH_API_SEQUENCE_VALUE_TRAITS_FLAG TH32CS_SNAPTHREAD
  94. #define WINSTL_TH_API_SEQUENCE_VALUE_TRAITS_CREATE_SNAPSHOT_FAIL_MESSAGE TEXT("Could not create thread list snapshot")
  95. #include <winstl/toolhelp/sequence_value_traits.hpp>
  96. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  97. /** \brief An STL collection for accessing thread information for a given process.
  98. *
  99. * \ingroup group__library__windows_toolhelp
  100. */
  101. typedef th_sequence_base<THREADENTRY32> thread_sequence;
  102. /** \brief Attribute shim for retrieving the process id associated with the THREADENTRY32 instance
  103. *
  104. * \ingroup group__library__windows_toolhelp
  105. *
  106. * \param te The THREADENTRY32 instance
  107. */
  108. inline DWORD get_pid(THREADENTRY32 const& te)
  109. {
  110. return te.th32OwnerProcessID;
  111. }
  112. /* ////////////////////////////////////////////////////////////////////// */
  113. #ifndef _WINSTL_NO_NAMESPACE
  114. # if defined(_STLSOFT_NO_NAMESPACE) || \
  115. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  116. } // namespace winstl
  117. # else
  118. } // namespace winstl_project
  119. } // namespace stlsoft
  120. # endif /* _STLSOFT_NO_NAMESPACE */
  121. #endif /* !_WINSTL_NO_NAMESPACE */
  122. /* ////////////////////////////////////////////////////////////////////// */
  123. #endif /* WINSTL_INCL_WINSTL_TOOLHELP_HPP_THREAD_SEQUENCE */
  124. /* ///////////////////////////// end of file //////////////////////////// */