diff options
Diffstat (limited to '')
-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 | ||