1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// Windows/Handle.h 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __WINDOWS_HANDLE_H 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __WINDOWS_HANDLE_H 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 6baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NWindows { 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 8baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CHandle 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 10baa3858d3f5d128a5c8466b700098109edcad5f2repo syncprotected: 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync HANDLE _handle; 12baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic: 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync operator HANDLE() { return _handle; } 14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CHandle(): _handle(NULL) {} 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ~CHandle() { Close(); } 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool IsCreated() const { return (_handle != NULL); } 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool Close() 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (_handle == NULL) 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return true; 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!::CloseHandle(_handle)) 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return false; 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _handle = NULL; 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return true; 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void Attach(HANDLE handle) { _handle = handle; } 27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync HANDLE Detach() 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync HANDLE handle = _handle; 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _handle = NULL; 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return handle; 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 38