Mercurial > vba-linux
annotate src/win32/7zip/7z/CPP/Windows/Handle.h @ 5:8fe0c57e53d2
concentrating on lua first
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:39:40 -0600 |
parents | f9f4f1b99eed |
children |
rev | line source |
---|---|
rlm@1 | 1 // Windows/Handle.h |
rlm@1 | 2 |
rlm@1 | 3 #ifndef __WINDOWS_HANDLE_H |
rlm@1 | 4 #define __WINDOWS_HANDLE_H |
rlm@1 | 5 |
rlm@1 | 6 namespace NWindows { |
rlm@1 | 7 |
rlm@1 | 8 class CHandle |
rlm@1 | 9 { |
rlm@1 | 10 protected: |
rlm@1 | 11 HANDLE _handle; |
rlm@1 | 12 public: |
rlm@1 | 13 operator HANDLE() { return _handle; } |
rlm@1 | 14 CHandle(): _handle(NULL) {} |
rlm@1 | 15 ~CHandle() { Close(); } |
rlm@1 | 16 bool Close() |
rlm@1 | 17 { |
rlm@1 | 18 if (_handle == NULL) |
rlm@1 | 19 return true; |
rlm@1 | 20 if (!::CloseHandle(_handle)) |
rlm@1 | 21 return false; |
rlm@1 | 22 _handle = NULL; |
rlm@1 | 23 return true; |
rlm@1 | 24 } |
rlm@1 | 25 void Attach(HANDLE handle) |
rlm@1 | 26 { _handle = handle; } |
rlm@1 | 27 HANDLE Detach() |
rlm@1 | 28 { |
rlm@1 | 29 HANDLE handle = _handle; |
rlm@1 | 30 _handle = NULL; |
rlm@1 | 31 return handle; |
rlm@1 | 32 } |
rlm@1 | 33 }; |
rlm@1 | 34 |
rlm@1 | 35 } |
rlm@1 | 36 |
rlm@1 | 37 #endif |