aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/Handle.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Handle.h
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to 'CPP/Windows/Handle.h')
-rw-r--r--CPP/Windows/Handle.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/CPP/Windows/Handle.h b/CPP/Windows/Handle.h
new file mode 100644
index 0000000..5878c83
--- /dev/null
+++ b/CPP/Windows/Handle.h
@@ -0,0 +1,39 @@
1// Windows/Handle.h
2
3#ifndef __WINDOWS_HANDLE_H
4#define __WINDOWS_HANDLE_H
5
6#include "../Common/MyTypes.h"
7
8namespace NWindows {
9
10class CHandle MY_UNCOPYABLE
11{
12protected:
13 HANDLE _handle;
14public:
15 operator HANDLE() { return _handle; }
16 CHandle(): _handle(NULL) {}
17 ~CHandle() { Close(); }
18 bool IsCreated() const { return (_handle != NULL); }
19 bool Close()
20 {
21 if (_handle == NULL)
22 return true;
23 if (!::CloseHandle(_handle))
24 return false;
25 _handle = NULL;
26 return true;
27 }
28 void Attach(HANDLE handle) { _handle = handle; }
29 HANDLE Detach()
30 {
31 HANDLE handle = _handle;
32 _handle = NULL;
33 return handle;
34 }
35};
36
37}
38
39#endif