This source file includes following definitions.
- pNetApiBufferFree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 } }