Mercurial > vba-clojure
diff src/win32/7zip/7z/CPP/Windows/Handle.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/Windows/Handle.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,37 @@ 1.4 +// Windows/Handle.h 1.5 + 1.6 +#ifndef __WINDOWS_HANDLE_H 1.7 +#define __WINDOWS_HANDLE_H 1.8 + 1.9 +namespace NWindows { 1.10 + 1.11 +class CHandle 1.12 +{ 1.13 +protected: 1.14 + HANDLE _handle; 1.15 +public: 1.16 + operator HANDLE() { return _handle; } 1.17 + CHandle(): _handle(NULL) {} 1.18 + ~CHandle() { Close(); } 1.19 + bool Close() 1.20 + { 1.21 + if (_handle == NULL) 1.22 + return true; 1.23 + if (!::CloseHandle(_handle)) 1.24 + return false; 1.25 + _handle = NULL; 1.26 + return true; 1.27 + } 1.28 + void Attach(HANDLE handle) 1.29 + { _handle = handle; } 1.30 + HANDLE Detach() 1.31 + { 1.32 + HANDLE handle = _handle; 1.33 + _handle = NULL; 1.34 + return handle; 1.35 + } 1.36 +}; 1.37 + 1.38 +} 1.39 + 1.40 +#endif