diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Handle.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-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.h | 39 |
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 | |||
8 | namespace NWindows { | ||
9 | |||
10 | class CHandle MY_UNCOPYABLE | ||
11 | { | ||
12 | protected: | ||
13 | HANDLE _handle; | ||
14 | public: | ||
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 | ||