root/experimental/NT-based/NTSpecific/NetAPIDeallocator.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pNetApiBufferFree

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

/* [<][>][^][v][top][bottom][index][help] */