rlm@1: // Windows/Handle.h rlm@1: rlm@1: #ifndef __WINDOWS_HANDLE_H rlm@1: #define __WINDOWS_HANDLE_H rlm@1: rlm@1: namespace NWindows { rlm@1: rlm@1: class CHandle rlm@1: { rlm@1: protected: rlm@1: HANDLE _handle; rlm@1: public: rlm@1: operator HANDLE() { return _handle; } rlm@1: CHandle(): _handle(NULL) {} rlm@1: ~CHandle() { Close(); } rlm@1: bool Close() rlm@1: { rlm@1: if (_handle == NULL) rlm@1: return true; rlm@1: if (!::CloseHandle(_handle)) rlm@1: return false; rlm@1: _handle = NULL; rlm@1: return true; rlm@1: } rlm@1: void Attach(HANDLE handle) rlm@1: { _handle = handle; } rlm@1: HANDLE Detach() rlm@1: { rlm@1: HANDLE handle = _handle; rlm@1: _handle = NULL; rlm@1: return handle; rlm@1: } rlm@1: }; rlm@1: rlm@1: } rlm@1: rlm@1: #endif