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