00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00052 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE
00053 #define WINSTL_INCL_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE
00054
00055 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00056 # define WINSTL_VER_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE_MAJOR 2
00057 # define WINSTL_VER_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE_MINOR 2
00058 # define WINSTL_VER_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE_REVISION 2
00059 # define WINSTL_VER_WINSTL_SYSTEM_HPP_PROCESS_MODULE_SEQUENCE_EDIT 48
00060 #endif
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00077 # include <winstl/winstl.h>
00078 #endif
00079 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00080 # ifndef WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS
00081 # include <winstl/error/exceptions.hpp>
00082 # endif
00083 #endif
00084 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00085 # include <winstl/memory/processheap_allocator.hpp>
00086 #endif
00087 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00088 # include <stlsoft/memory/auto_buffer.hpp>
00089 #endif
00090 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00091 # include <stlsoft/collections/util/collections.hpp>
00092 #endif
00093 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00094 # include <stlsoft/util/std/iterator_helper.hpp>
00095 #endif
00096 #if !defined(_PSAPI_H_) && \
00097 !defined(_PSAPI_H)
00098 # ifndef WINSTL_INCL_WINSTL_DL_HPP_DL_CALL
00099 # include <winstl/dl/dl_call.hpp>
00100 # endif
00101 #endif
00102
00103 #if !defined(STLSOFT_UNITTEST)
00104 # include <algorithm>
00105 #endif
00106
00107
00108
00109
00110
00111 #ifndef _WINSTL_NO_NAMESPACE
00112 # if defined(_STLSOFT_NO_NAMESPACE) || \
00113 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00114
00115 namespace winstl
00116 {
00117 # else
00118
00119
00120 namespace stlsoft
00121 {
00122
00123 namespace winstl_project
00124 {
00125
00126 # endif
00127 #endif
00128
00129
00130
00131
00132
00137 class process_module_sequence
00138 : public stlsoft_ns_qual(stl_collection_tag)
00139 {
00142 public:
00144 typedef HMODULE value_type;
00146 typedef processheap_allocator<value_type> allocator_type;
00148 typedef process_module_sequence class_type;
00150 typedef value_type const* const_pointer;
00152 typedef value_type const& const_reference;
00154 typedef stlsoft_ns_qual(pointer_iterator)< value_type
00155 , const_pointer
00156 , const_reference
00157 >::type const_iterator;
00159 typedef ws_size_t size_type;
00161 typedef ws_ptrdiff_t difference_type;
00162 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00164 typedef stlsoft_ns_qual(const_reverse_bidirectional_iterator_base)< const_iterator
00165 , value_type
00166 , const_reference
00167 , const_pointer
00168 , difference_type
00169 > const_reverse_iterator;
00170 #endif
00172
00175 public:
00177 ss_explicit_k process_module_sequence(HANDLE hProcess);
00179 process_module_sequence(class_type const& rhs);
00181 ~process_module_sequence() stlsoft_throw_0();
00183
00186 public:
00190 const_iterator begin() const;
00194 const_iterator end() const;
00195
00196 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00200 const_reverse_iterator rbegin() const;
00204 const_reverse_iterator rend() const;
00205 #endif
00207
00210 public:
00214 const_reference operator [](size_type index) const;
00216
00219 public:
00221 ws_bool_t empty() const;
00223 size_type size() const;
00225
00228 private:
00229 typedef stlsoft_ns_qual(auto_buffer_old)< value_type
00230 , allocator_type
00231 , 64
00232 > buffer_type_;
00233
00234 buffer_type_ m_modules;
00236
00239 private:
00240 class_type& operator =(class_type const&);
00242 };
00243
00245
00246
00247 #ifdef STLSOFT_UNITTEST
00248 # include "./unittest/process_module_sequence_unittest_.h"
00249 #endif
00250
00251
00252
00253
00254
00255 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00256
00257 inline process_module_sequence::process_module_sequence(HANDLE hProcess)
00258 : m_modules(buffer_type_::internal_size())
00259 {
00260 DWORD cbReturned;
00261
00262 for(;;)
00263 {
00264 #if defined(_PSAPI_H_) || \
00265 defined(_PSAPI_H)
00266 if(!::EnumProcessModules(hProcess, &m_modules[0], sizeof(value_type) * m_modules.size(), &cbReturned))
00267 #else
00268 if(!dl_call<BOOL>( "PSAPI.DLL"
00269 , WINSTL_DL_CALL_WINx_STDCALL_LITERAL("EnumProcessModules")
00270 , hProcess
00271 , &m_modules[0]
00272 , sizeof(value_type) * m_modules.size()
00273 , &cbReturned))
00274 #endif
00275 {
00276 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00277 STLSOFT_THROW_X(windows_exception("Failed to enumerate processes", ::GetLastError()));
00278 #else
00279 m_modules.resize(0);
00280
00281 break;
00282 #endif
00283 }
00284 else
00285 {
00286 const ws_size_t n = cbReturned / sizeof(value_type);
00287
00288 if(n < m_modules.size())
00289 {
00290 m_modules.resize(n);
00291
00292 break;
00293 }
00294 else
00295 {
00296 const size_type size = m_modules.size();
00297
00298 m_modules.resize(1);
00299
00300 if(!m_modules.resize(2 * size))
00301 {
00302
00303
00304 m_modules.resize(0);
00305
00306 break;
00307 }
00308 }
00309 }
00310 }
00311 }
00312
00313 inline process_module_sequence::process_module_sequence(process_module_sequence const& rhs)
00314 : m_modules(rhs.m_modules.size())
00315 {
00316 stlsoft_ns_qual_std(copy)(rhs.m_modules.begin(), rhs.m_modules.end(), m_modules.begin());
00317 }
00318
00319 inline process_module_sequence::~process_module_sequence() stlsoft_throw_0()
00320 {}
00321
00322 inline process_module_sequence::const_iterator process_module_sequence::begin() const
00323 {
00324 return &*m_modules.begin();
00325 }
00326
00327 inline process_module_sequence::const_iterator process_module_sequence::end() const
00328 {
00329 return &*m_modules.end();
00330 }
00331
00332 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00333 inline process_module_sequence::const_reverse_iterator process_module_sequence::rbegin() const
00334 {
00335 return const_reverse_iterator(end());
00336 }
00337
00338 inline process_module_sequence::const_reverse_iterator process_module_sequence::rend() const
00339 {
00340 return const_reverse_iterator(begin());
00341 }
00342 #endif
00343
00344 inline process_module_sequence::const_reference process_module_sequence::operator [](process_module_sequence::size_type index) const
00345 {
00346 WINSTL_MESSAGE_ASSERT("Index out of range", index < size());
00347
00348 return m_modules[index];
00349 }
00350
00351 inline ws_bool_t process_module_sequence::empty() const
00352 {
00353 return m_modules.empty();
00354 }
00355
00356 inline process_module_sequence::size_type process_module_sequence::size() const
00357 {
00358 return m_modules.size();
00359 }
00360
00361 #endif
00362
00363
00364
00365
00366
00367 #ifndef _WINSTL_NO_NAMESPACE
00368 # if defined(_STLSOFT_NO_NAMESPACE) || \
00369 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00370 }
00371 # else
00372 }
00373 }
00374 # endif
00375 #endif
00376
00377
00378
00379 #endif
00380
00381