other-licenses/7zstub/src/Windows/Handle.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial