1 // Windows/Handle.h
2 
3 #ifndef __WINDOWS_HANDLE_H
4 #define __WINDOWS_HANDLE_H
5 
6 namespace NWindows {
7 
8 class CHandle
9 {
10 protected:
11   HANDLE _handle;
12 public:
HANDLE()13   operator HANDLE() { return _handle; }
CHandle()14   CHandle(): _handle(NULL) {}
~CHandle()15   ~CHandle() { Close(); }
IsCreated()16   bool IsCreated() const { return (_handle != NULL); }
Close()17   bool Close()
18   {
19     if (_handle == NULL)
20       return true;
21     if (!::CloseHandle(_handle))
22       return false;
23     _handle = NULL;
24     return true;
25   }
Attach(HANDLE handle)26   void Attach(HANDLE handle) { _handle = handle; }
Detach()27   HANDLE Detach()
28   {
29     HANDLE handle = _handle;
30     _handle = NULL;
31     return handle;
32   }
33 };
34 
35 }
36 
37 #endif
38