libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
NetAPIDeallocator.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "../../../core/deleter.hpp"
20 
21 #include <boost/noncopyable.hpp>
22 
23 /////////////////////////////////////////////////////////////////////////////
24 
25 namespace jmmcg { namespace NTUtils {
26 
27  const TCHAR netapi32_nt_lib_name[]=_T("netapi32.dll");
28  const TCHAR NetApiBufferFree_name[]=_T("NetApiBufferFree");
30 
31  template <class T>
32  struct NetEnumDeallocator : std::unary_function<T, void> {
34 
35  result_type __fastcall operator()(argument_type *t) const {
36  if (t) {
37  if (*t) {
38  register DWORD ret=::WNetCloseEnum(*t);
39  JMMCG_TRACE(_T("NetEnumDeallocator::~operator()(): Windows error code: ")<<win_exception::StrFromWinErr(ret!=NO_ERROR ? ::GetLastError() : 0));
40  }
41  deleter_t().operator()(t);
42  }
43  }
44  };
45 
46  template <class T>
47  class NetAPIDeallocator : public std::unary_function<T, void>,virtual private LoadLibraryWrapper, private boost::noncopyable {
48  public:
49  __stdcall NetAPIDeallocator()
52  assert(pNetApiBufferFree);
53  }
54 
55  result_type __stdcall operator()(argument_type *t) const {
56  if (t) {
57  register NET_API_STATUS ret=(*pNetApiBufferFree)(t);
58  JMMCG_TRACE(_T("NetAPIDeallocator::~operator()(): Windows error code: ")<<win_exception::StrFromWinErr(ret!=NO_ERROR ? ::GetLastError() : 0));
59  }
60  }
61 
62  private:
63  const pNetApiBufferFreeType pNetApiBufferFree;
64  };
65 
66 } }